Skip to content

Commit

Permalink
compression/huffman: debug function bails upon disaster (CID 1517261)
Browse files Browse the repository at this point in the history
We shouldn't get a node with a zero code, and there's probably nothing
to do but stop.

   CID 1517261 (#1-2 of 2): Bad bit shift operation
   (BAD_SHIFT)11. negative_shift: In expression j >> offset - k,
   shifting by a negative amount has undefined behavior. The shift
   amount, offset - k, is -3.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Mon Dec 19 23:29:04 UTC 2022 on sn-devel-184
  • Loading branch information
douglasbagnall authored and jrasamba committed Dec 19, 2022
1 parent 628f14c commit 44a4400
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/compression/lzxpress_huffman.c
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,11 @@ static void debug_tree_codes(struct bitstream *input)
int k;
uint16_t j = q.code_code;
size_t offset = bitlen_nonzero_16(j) - 1;
if (unlikely(j == 0)) {
DBG("BROKEN code is 0!\n");
return;
}

for (k = 0; k <= offset; k++) {
bool b = (j >> (offset - k)) & 1;
bits[k] = b ? '1' : '0';
Expand Down

0 comments on commit 44a4400

Please sign in to comment.