compression/huffman: avoid semi-defined behaviour in decompress
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Sat, 3 Dec 2022 22:33:29 +0000 (11:33 +1300)
committerJeremy Allison <jra@samba.org>
Mon, 19 Dec 2022 22:32:35 +0000 (22:32 +0000)
commit6f77b376d470dd318f0a9699b3528018ce8ea49a
tree460bcf8d1f1492863c591cc1ef0c413334f289eb
parent80c0b416892bfacc0d919fe032461748d7962f05
compression/huffman: avoid semi-defined behaviour in decompress

We had

               output[output_pos - distance];

where output_pos and distance are size_t and distance can be greater
than output_pos (because it refers to a place in the previous block).

The underflow is defined, leading to a big number, and when
sizeof(size_t) == sizeof(*uint8_t) the subsequent overflow works as
expected. But if size_t is smaller than a pointer, bad things will
happen.

This was found by OSSFuzz with
'UBSAN_OPTIONS=print_stacktrace=1:silence_unsigned_overflow=1'.

Credit to OSSFuzz.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/compression/lzxpress_huffman.c