mirror of
https://github.com/postgres/postgres.git
synced 2025-06-03 00:02:26 -04:00
Second thoughts on TOAST decompression.
On detecting a corrupted match tag, pglz_decompress() should just summarily return -1. Breaking out of the loop, as I did in dfc797730, doesn't quite guarantee that will happen. Also, we can use unlikely() on that check, just in case it helps. Backpatch to v13, like the previous patch.
This commit is contained in:
parent
57fae192f8
commit
7957e75c58
@ -680,9 +680,12 @@ pglz_compress(const char *source, int32 slen, char *dest,
|
|||||||
* pglz_decompress -
|
* pglz_decompress -
|
||||||
*
|
*
|
||||||
* Decompresses source into dest. Returns the number of bytes
|
* Decompresses source into dest. Returns the number of bytes
|
||||||
* decompressed in the destination buffer, and *optionally*
|
* decompressed into the destination buffer, or -1 if the
|
||||||
* checks that both the source and dest buffers have been
|
* compressed data is corrupted.
|
||||||
* fully read and written to, respectively.
|
*
|
||||||
|
* If check_complete is true, the data is considered corrupted
|
||||||
|
* if we don't exactly fill the destination buffer. Callers that
|
||||||
|
* are extracting a slice typically can't apply this check.
|
||||||
* ----------
|
* ----------
|
||||||
*/
|
*/
|
||||||
int32
|
int32
|
||||||
@ -736,8 +739,8 @@ pglz_decompress(const char *source, int32 slen, char *dest,
|
|||||||
* must check this, else we risk an infinite loop below in the
|
* must check this, else we risk an infinite loop below in the
|
||||||
* face of corrupt data.)
|
* face of corrupt data.)
|
||||||
*/
|
*/
|
||||||
if (sp > srcend || off == 0)
|
if (unlikely(sp > srcend || off == 0))
|
||||||
break;
|
return -1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Don't emit more data than requested.
|
* Don't emit more data than requested.
|
||||||
@ -809,9 +812,7 @@ pglz_decompress(const char *source, int32 slen, char *dest,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check we decompressed the right amount. If we are slicing, then we
|
* If requested, check we decompressed the right amount.
|
||||||
* won't necessarily be at the end of the source or dest buffers when we
|
|
||||||
* hit a stop, so we don't test them.
|
|
||||||
*/
|
*/
|
||||||
if (check_complete && (dp != destend || sp != srcend))
|
if (check_complete && (dp != destend || sp != srcend))
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user