Improve pglz_decompress's defenses against corrupt compressed data.
commitcfa4eba02c878d69e7f2c7bf8895a393521bc013
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 19 Oct 2023 00:43:17 +0000 (18 20:43 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 19 Oct 2023 00:43:17 +0000 (18 20:43 -0400)
tree18a99f18b8a38f9969ac05d67eae66fe3de85b93
parent418d6b4430a5dbfbe4dd9c10ada367f0aee88b52
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