Coverage Report

Created: 2026-01-16 06:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/exiv2/src/jp2image_int.cpp
Line
Count
Source
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
3
#include "jp2image_int.hpp"
4
5
#include "types.hpp"
6
7
#include <cassert>
8
#include <cstdint>
9
#include <vector>
10
11
namespace Exiv2::Internal {
12
13
351
bool isValidBoxFileType(const std::vector<uint8_t>& boxData) {
14
  // BR & MinV are obligatory (4 + 4 bytes). Afterwards we have N compatibility lists (of size 4)
15
351
  if (boxData.size() < 8 || ((boxData.size() - 8u) % 4u) != 0) {
16
36
    return false;
17
36
  }
18
19
315
  const size_t N = (boxData.size() - 8u) / 4u;
20
315
  const uint32_t brand = getULong(boxData.data(), bigEndian);
21
315
  const uint32_t minorVersion = getULong(boxData.data() + 4, bigEndian);
22
23
315
  bool clWithRightBrand = false;
24
2.02k
  for (size_t i = 0; i < N; i++) {
25
1.87k
    uint32_t compatibilityList = getULong(boxData.data() + 8 + (i * 4), bigEndian);
26
1.87k
    if ((brand == brandJp2 && compatibilityList == brandJp2) || (brand == brandJph && compatibilityList == brandJph)) {
27
171
      clWithRightBrand = true;
28
171
      break;
29
171
    }
30
1.87k
  }
31
315
  return (minorVersion == 0 && clWithRightBrand);
32
351
}
33
}  // namespace Exiv2::Internal