Skip to content

Commit

Permalink
Fix UnpackBits (#4227)
Browse files Browse the repository at this point in the history
In UnpackBits I re-filled the buffer even if the amount of bits in the buffer was equal to the number of bits read. As a result, when the last value was read and the buffer was empty, I would still re-fill it, causing an out-of-bounds read.

Signed-off-by: Szymon Karpiński <skarpinski@nvidia.com>
  • Loading branch information
szkarpinski committed Sep 6, 2022
1 parent 7cd5566 commit 41e8107
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion dali/imgcodec/decoders/libtiff/tiff_libtiff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void DLL_PUBLIC UnpackBits(size_t nbits, OutputType *out, const void *in, size_t
OutputType result = 0;
size_t bits_to_read = nbits;
while (bits_to_read > 0) {
if (bits_in_buffer > bits_to_read) {
if (bits_in_buffer >= bits_to_read) {
// If we have enough bits in the buffer, we store them and finish
result <<= bits_to_read;
result |= buffer >> (buffer_capacity - bits_to_read);
Expand Down

0 comments on commit 41e8107

Please sign in to comment.