]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
compression/huffman: debug function bails upon disaster (CID 1517261)
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Tue, 6 Dec 2022 20:27:00 +0000 (09:27 +1300)
committerJeremy Allison <jra@samba.org>
Mon, 19 Dec 2022 23:29:04 +0000 (23:29 +0000)
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

lib/compression/lzxpress_huffman.c

index e6ff4ed3b02b78269f71090355aea135764142d3..3eac8e3b2b6cd89a0232b540e642bea31801ebf7 100644 (file)
@@ -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';