From: Douglas Bagnall Date: Mon, 5 Dec 2022 22:24:22 +0000 (+1300) Subject: compression/huffman: check again for invalid codes (CID 1517302) X-Git-Tag: talloc-2.4.0~204 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d6a67908e13dd46b3bd336adae97e26920bb7f90;p=thirdparty%2Fsamba.git compression/huffman: check again for invalid codes (CID 1517302) We know that code is non-zero, because it comes from the combination of the intermediate representation and the symbol tables that were generated at the same time. But Coverity doesn't know that, and it thinks we could be doing undefined things in the subsequent shift. CID 1517302: Integer handling issues (BAD_SHIFT) In expression "1 << code_bit_len", shifting by a negative amount has Signed-off-by: Douglas Bagnall Reviewed-by: Jeremy Allison --- diff --git a/lib/compression/lzxpress_huffman.c b/lib/compression/lzxpress_huffman.c index 7dd91f687fe..c8e92383002 100644 --- a/lib/compression/lzxpress_huffman.c +++ b/lib/compression/lzxpress_huffman.c @@ -970,6 +970,9 @@ static inline bool write_bits(struct write_context *wc, static inline bool write_code(struct write_context *wc, uint16_t code) { int code_bit_len = bitlen_nonzero_16(code); + if (unlikely(code == 0)) { + return false; + } code &= (1 << code_bit_len) - 1; return write_bits(wc, code, code_bit_len); }