Coverage Report

Created: 2026-03-31 07:44

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
38
void ResetExifOrientation(std::vector<uint8_t>& exif) {
18
38
  if (exif.size() < 12) return;  // not enough bytes for a valid exif blob
19
38
  bool bigendian;
20
38
  uint8_t* t = exif.data();
21
38
  if (LoadLE32(t) == 0x2A004D4D) {
22
18
    bigendian = true;
23
20
  } else if (LoadLE32(t) == 0x002A4949) {
24
20
    bigendian = false;
25
20
  } else {
26
0
    return;  // not a valid tiff header
27
0
  }
28
38
  t += 4;
29
38
  uint64_t offset = (bigendian ? LoadBE32(t) : LoadLE32(t));
30
38
  if (exif.size() < 12 + offset + 2 || offset < 8) return;
31
35
  t += offset - 4;
32
35
  uint16_t nb_tags = (bigendian ? LoadBE16(t) : LoadLE16(t));
33
35
  t += 2;
34
799
  while (nb_tags > 0) {
35
795
    if (t + 12 >= exif.data() + exif.size()) return;
36
775
    uint16_t tag = (bigendian ? LoadBE16(t) : LoadLE16(t));
37
775
    t += 2;
38
775
    if (tag == kExifOrientationTag) {
39
11
      uint16_t type = (bigendian ? LoadBE16(t) : LoadLE16(t));
40
11
      t += 2;
41
11
      uint32_t count = (bigendian ? LoadBE32(t) : LoadLE32(t));
42
11
      t += 4;
43
11
      if (type == 3 && count == 1) {
44
5
        if (bigendian) {
45
1
          StoreBE16(1, t);
46
4
        } else {
47
4
          StoreLE16(1, t);
48
4
        }
49
5
      }
50
11
      return;
51
764
    } else {
52
764
      t += 10;
53
764
      nb_tags--;
54
764
    }
55
775
  }
56
35
}
57
58
}  // namespace jxl