Coverage Report

Created: 2025-08-29 06:07

/src/woff2/src/woff2_common.cc
Line
Count
Source
1
/* Copyright 2013 Google Inc. All Rights Reserved.
2
3
   Distributed under MIT license.
4
   See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
*/
6
7
/* Helpers common across multiple parts of woff2 */
8
9
#include <algorithm>
10
11
#include "./woff2_common.h"
12
13
#include "./port.h"
14
15
namespace woff2 {
16
17
18
227k
uint32_t ComputeULongSum(const uint8_t* buf, size_t size) {
19
227k
  uint32_t checksum = 0;
20
227k
  size_t aligned_size = size & ~3;
21
17.3M
  for (size_t i = 0; i < aligned_size; i += 4) {
22
17.0M
    checksum +=
23
17.0M
        (buf[i] << 24) | (buf[i + 1] << 16) | (buf[i + 2] << 8) | buf[i + 3];
24
17.0M
  }
25
26
  // treat size not aligned on 4 as if it were padded to 4 with 0's
27
227k
  if (size != aligned_size) {
28
112k
    uint32_t v = 0;
29
336k
    for (size_t i = aligned_size; i < size; ++i) {
30
223k
      v |= buf[i] << (24 - 8 * (i & 3));
31
223k
    }
32
112k
    checksum += v;
33
112k
  }
34
35
227k
  return checksum;
36
227k
}
37
38
914
size_t CollectionHeaderSize(uint32_t header_version, uint32_t num_fonts) {
39
914
  size_t size = 0;
40
914
  if (header_version == 0x00020000) {
41
558
    size += 12;  // ulDsig{Tag,Length,Offset}
42
558
  }
43
914
  if (header_version == 0x00010000 || header_version == 0x00020000) {
44
914
    size += 12   // TTCTag, Version, numFonts
45
914
      + 4 * num_fonts;  // OffsetTable[numFonts]
46
914
  }
47
914
  return size;
48
914
}
49
50
} // namespace woff2