Coverage Report

Created: 2025-07-23 08:18

/src/libjxl/lib/jxl/dec_bit_reader.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/jxl/dec_bit_reader.h"
7
8
#include <cstddef>
9
#include <cstdint>
10
11
#include "lib/jxl/base/common.h"
12
#include "lib/jxl/base/status.h"
13
14
namespace jxl {
15
16
259M
void BitReader::BoundsCheckedRefill() {
17
259M
  const uint8_t* end = end_minus_8_ + 8;
18
19
  // Read whole bytes until we have [56, 64) bits (same as LoadLE64)
20
260M
  for (; bits_in_buf_ < 64 - kBitsPerByte; bits_in_buf_ += kBitsPerByte) {
21
92.0M
    if (next_byte_ >= end) break;
22
341k
    buf_ |= static_cast<uint64_t>(*next_byte_++) << bits_in_buf_;
23
341k
  }
24
259M
  JXL_DASSERT(bits_in_buf_ < 64);
25
26
  // Add extra bytes as 0 at the end of the stream in the bit_buffer_. If
27
  // these bits are read, Close() will return a failure.
28
259M
  size_t extra_bytes = (63 - bits_in_buf_) / kBitsPerByte;
29
259M
  overread_bytes_ += extra_bytes;
30
259M
  bits_in_buf_ += extra_bytes * kBitsPerByte;
31
32
259M
  JXL_DASSERT(bits_in_buf_ < 64);
33
259M
  JXL_DASSERT(bits_in_buf_ >= 56);
34
259M
}
35
36
}  // namespace jxl