Skip to content

Commit 041c80a

Browse files
committed
jchuff.c/flush_bits(): Guard against put_bits < 0
This fixes a UBSan negative shift warning, reported by OSS-Fuzz, that occurred when attempting to transform a specially-crafted malformed arithmetic-coded JPEG image into a baseline Huffman-coded JPEG destination image with default Huffman tables. This issue probably had a similar root cause to the issue fixed in 31a3013, but in this case, the issue only occurred with the SIMD baseline Huffman encoder in libjpeg-turbo 2.1.x. It was not reproducible in 2.0.x or 3.0.x or when using the C baseline Huffman encoder.
1 parent 58cee6d commit 041c80a

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

jchuff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ flush_bits(working_state *state)
518518
temp = (JOCTET)(put_buffer >> put_bits);
519519
EMIT_BYTE(temp)
520520
}
521-
if (put_bits) {
521+
if (put_bits > 0) {
522522
/* fill partial byte with ones */
523523
temp = (JOCTET)((put_buffer << (8 - put_bits)) | (0xFF >> put_bits));
524524
EMIT_BYTE(temp)

0 commit comments

Comments
 (0)