Improve pglz_decompress's defenses against corrupt compressed data.
authorTom Lane <[email protected]>
Thu, 19 Oct 2023 00:43:17 +0000 (20:43 -0400)
committerTom Lane <[email protected]>
Thu, 19 Oct 2023 00:43:17 +0000 (20:43 -0400)
commit2c63dc0356b3573382821bb67c869e95646b6f6d
tree1f9884c3dbf31f2b8e7877eaa52895e290e1400b
parent0a8b7d5c11266ba5291d0aafc0ff4f92ab1cc041
Improve pglz_decompress's defenses against corrupt compressed data.

When processing a match tag, check to see if the claimed "off"
is more than the distance back to the output buffer start.
If it is, then the data is corrupt, and what's more we would
fetch from outside the buffer boundaries and potentially incur
a SIGSEGV.  (Although the odds of that seem relatively low, given
that "off" can't be more than 4K.)

Back-patch to v13; before that, this function wasn't really
trying to protect against bad data.

Report and fix by Flavien Guedez.

Discussion: https://postgr.es/m/01fc0593-e31e-463d-902c-dd43174acee2@oopacity.net
src/common/pg_lzcompress.c