Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfd29975

Browse files
committed
Second thoughts on TOAST decompression.
On detecting a corrupted match tag, pglz_decompress() should justsummarily return -1. Breaking out of the loop, as I did indfc7977,doesn't quite guarantee that will happen. Also, we can useunlikely() on that check, just in case it helps.Backpatch to v13, like the previous patch.
1 parentdd26a0a commitfd29975

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

‎src/common/pg_lzcompress.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,12 @@ pglz_compress(const char *source, int32 slen, char *dest,
680680
* pglz_decompress -
681681
*
682682
*Decompresses source into dest. Returns the number of bytes
683-
*decompressed in the destination buffer, and *optionally*
684-
*checks that both the source and dest buffers have been
685-
*fully read and written to, respectively.
683+
*decompressed into the destination buffer, or -1 if the
684+
*compressed data is corrupted.
685+
*
686+
*If check_complete is true, the data is considered corrupted
687+
*if we don't exactly fill the destination buffer. Callers that
688+
*are extracting a slice typically can't apply this check.
686689
* ----------
687690
*/
688691
int32
@@ -736,8 +739,8 @@ pglz_decompress(const char *source, int32 slen, char *dest,
736739
* must check this, else we risk an infinite loop below in the
737740
* face of corrupt data.)
738741
*/
739-
if (sp>srcend||off==0)
740-
break;
742+
if (unlikely(sp>srcend||off==0))
743+
return-1;
741744

742745
/*
743746
* Don't emit more data than requested.
@@ -809,9 +812,7 @@ pglz_decompress(const char *source, int32 slen, char *dest,
809812
}
810813

811814
/*
812-
* Check we decompressed the right amount. If we are slicing, then we
813-
* won't necessarily be at the end of the source or dest buffers when we
814-
* hit a stop, so we don't test them.
815+
* If requested, check we decompressed the right amount.
815816
*/
816817
if (check_complete&& (dp!=destend||sp!=srcend))
817818
return-1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp