Coverage Report

Created: 2026-08-14 08:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjxl/lib/extras/exif.cc
Line
Count
Source
1
// Copyright (c) the JPEG XL Project Authors. All rights reserved.
2
//
3
// Use of this source code is governed by a BSD-style
4
// license that can be found in the LICENSE file.
5
6
#include "lib/extras/exif.h"
7
8
#include <cstdint>
9
#include <vector>
10
11
#include "lib/jxl/base/byte_order.h"
12
13
namespace jxl {
14
15
constexpr uint16_t kExifOrientationTag = 274;
16
17
11
void ResetExifOrientation(std::vector<uint8_t>& exif) {
18
11
  if (exif.size() < 12) return;  // not enough bytes for a valid exif blob
19
11
  bool bigendian;
20
11
  uint8_t* t = exif.data();
21
11
  if (LoadLE32(t) == 0x2A004D4D) {
22
0
    bigendian = true;
23
11
  } else if (LoadLE32(t) == 0x002A4949) {
24
11
    bigendian = false;
25
11
  } else {
26
0
    return;  // not a valid tiff header
27
0
  }
28
11
  t += 4;
29
11
  uint64_t offset = (bigendian ? LoadBE32(t) : LoadLE32(t));
30
11
  if (exif.size() < 12 + offset + 2 || offset < 8) return;
31
9
  t += offset - 4;
32
9
  uint16_t nb_tags = (bigendian ? LoadBE16(t) : LoadLE16(t));
33
9
  t += 2;
34
319
  while (nb_tags > 0) {
35
316
    if (t + 12 >= exif.data() + exif.size()) return;
36
312
    uint16_t tag = (bigendian ? LoadBE16(t) : LoadLE16(t));
37
312
    t += 2;
38
312
    if (tag == kExifOrientationTag) {
39
2
      uint16_t type = (bigendian ? LoadBE16(t) : LoadLE16(t));
40
2
      t += 2;
41
2
      uint32_t count = (bigendian ? LoadBE32(t) : LoadLE32(t));
42
2
      t += 4;
43
2
      if (type == 3 && count == 1) {
44
1
        if (bigendian) {
45
0
          StoreBE16(1, t);
46
1
        } else {
47
1
          StoreLE16(1, t);
48
1
        }
49
1
      }
50
2
      return;
51
310
    } else {
52
310
      t += 10;
53
310
      nb_tags--;
54
310
    }
55
312
  }
56
9
}
57
58
}  // namespace jxl