pgsql: Fix heap-buffer-overflow in pglz_decompress() on corrupt input. - Mailing list pgsql-committers

From Andrew Dunstan
Subject pgsql: Fix heap-buffer-overflow in pglz_decompress() on corrupt input.
Date
Msg-id E1wBByO-000Iyp-24@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix heap-buffer-overflow in pglz_decompress() on corrupt input.

When decoding a match tag, pglz_decompress() reads 2 bytes (or 3
for extended-length matches) from the source buffer before checking
whether enough data remains.  The existing bounds check (sp > srcend)
occurs after the reads, so truncated compressed data that ends
mid-tag causes a read past the allocated buffer.

Fix by validating that sufficient source bytes are available before
reading each part of the match tag.  The post-read sp > srcend
check is no longer needed and is removed.

Found by fuzz testing with libFuzzer and AddressSanitizer.

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/2b5ba2a0a141f621f61cb732d776dc78269f879b

Modified Files
--------------
src/common/pg_lzcompress.c | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)


pgsql-committers by date:

Previous
From: Aleksander Alekseev
Date:
Subject: Re: pgsql: Allow autovacuum to use parallel vacuum workers.
Next
From: Andrew Dunstan
Date:
Subject: pgsql: Revert "Add built-in fuzzing harnesses for security testing."