Coverage Report

Created: 2026-09-28 06:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ots/subprojects/woff2-1.0.2/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
53.9k
uint32_t ComputeULongSum(const uint8_t* buf, size_t size) {
19
53.9k
  uint32_t checksum = 0;
20
53.9k
  size_t aligned_size = size & ~3;
21
3.30M
  for (size_t i = 0; i < aligned_size; i += 4) {
22
3.25M
#if defined(WOFF_LITTLE_ENDIAN)
23
3.25M
    uint32_t v = *reinterpret_cast<const uint32_t*>(buf + i);
24
3.25M
    checksum += (((v & 0xFF) << 24) | ((v & 0xFF00) << 8) |
25
3.25M
      ((v & 0xFF0000) >> 8) | ((v & 0xFF000000) >> 24));
26
#elif defined(WOFF_BIG_ENDIAN)
27
    checksum += *reinterpret_cast<const uint32_t*>(buf + i);
28
#else
29
    checksum += (buf[i] << 24) | (buf[i + 1] << 16) |
30
      (buf[i + 2] << 8) | buf[i + 3];
31
#endif
32
3.25M
  }
33
34
  // treat size not aligned on 4 as if it were padded to 4 with 0's
35
53.9k
  if (size != aligned_size) {
36
25.6k
    uint32_t v = 0;
37
76.7k
    for (size_t i = aligned_size; i < size; ++i) {
38
51.1k
      v |= buf[i] << (24 - 8 * (i & 3));
39
51.1k
    }
40
25.6k
    checksum += v;
41
25.6k
  }
42
43
53.9k
  return checksum;
44
53.9k
}
45
46
196
size_t CollectionHeaderSize(uint32_t header_version, uint32_t num_fonts) {
47
196
  size_t size = 0;
48
196
  if (header_version == 0x00020000) {
49
159
    size += 12;  // ulDsig{Tag,Length,Offset}
50
159
  }
51
196
  if (header_version == 0x00010000 || header_version == 0x00020000) {
52
196
    size += 12   // TTCTag, Version, numFonts
53
196
      + 4 * num_fonts;  // OffsetTable[numFonts]
54
196
  }
55
196
  return size;
56
196
}
57
58
} // namespace woff2