From: Tom Lane Date: Sun, 22 Mar 2026 22:06:48 +0000 (-0400) Subject: Fix finalization of decompressor astreamers. X-Git-Tag: REL_16_14~75 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=80785a527b9cf74b16cb5bb65355f94157124bf7;p=thirdparty%2Fpostgresql.git Fix finalization of decompressor astreamers. Send the correct amount of data to the next astreamer, not the whole allocated buffer size. This bug escaped detection because in present uses the next astreamer is always a tar-file parser which is insensitive to trailing garbage. But that may not be true in future uses. Author: Andrew Dunstan Reviewed-by: Tom Lane Discussion: https://postgr.es/m/2178517.1774064942@sss.pgh.pa.us Backpatch-through: 15 --- diff --git a/src/bin/pg_basebackup/bbstreamer_gzip.c b/src/bin/pg_basebackup/bbstreamer_gzip.c index c62265ac86f..94f3b9a4de5 100644 --- a/src/bin/pg_basebackup/bbstreamer_gzip.c +++ b/src/bin/pg_basebackup/bbstreamer_gzip.c @@ -323,10 +323,11 @@ bbstreamer_gzip_decompressor_finalize(bbstreamer *streamer) * End of the stream, if there is some pending data in output buffers then * we must forward it to next streamer. */ - bbstreamer_content(mystreamer->base.bbs_next, NULL, - mystreamer->base.bbs_buffer.data, - mystreamer->base.bbs_buffer.maxlen, - BBSTREAMER_UNKNOWN); + if (mystreamer->bytes_written > 0) + bbstreamer_content(mystreamer->base.bbs_next, NULL, + mystreamer->base.bbs_buffer.data, + mystreamer->bytes_written, + BBSTREAMER_UNKNOWN); bbstreamer_finalize(mystreamer->base.bbs_next); } diff --git a/src/bin/pg_basebackup/bbstreamer_lz4.c b/src/bin/pg_basebackup/bbstreamer_lz4.c index a9f57d56ac0..eaed289297d 100644 --- a/src/bin/pg_basebackup/bbstreamer_lz4.c +++ b/src/bin/pg_basebackup/bbstreamer_lz4.c @@ -395,10 +395,11 @@ bbstreamer_lz4_decompressor_finalize(bbstreamer *streamer) * End of the stream, if there is some pending data in output buffers then * we must forward it to next streamer. */ - bbstreamer_content(mystreamer->base.bbs_next, NULL, - mystreamer->base.bbs_buffer.data, - mystreamer->base.bbs_buffer.maxlen, - BBSTREAMER_UNKNOWN); + if (mystreamer->bytes_written > 0) + bbstreamer_content(mystreamer->base.bbs_next, NULL, + mystreamer->base.bbs_buffer.data, + mystreamer->bytes_written, + BBSTREAMER_UNKNOWN); bbstreamer_finalize(mystreamer->base.bbs_next); } diff --git a/src/bin/pg_basebackup/bbstreamer_zstd.c b/src/bin/pg_basebackup/bbstreamer_zstd.c index 6e220a2ebd7..71759ba3cca 100644 --- a/src/bin/pg_basebackup/bbstreamer_zstd.c +++ b/src/bin/pg_basebackup/bbstreamer_zstd.c @@ -343,7 +343,7 @@ bbstreamer_zstd_decompressor_finalize(bbstreamer *streamer) if (mystreamer->zstd_outBuf.pos > 0) bbstreamer_content(mystreamer->base.bbs_next, NULL, mystreamer->base.bbs_buffer.data, - mystreamer->base.bbs_buffer.maxlen, + mystreamer->zstd_outBuf.pos, BBSTREAMER_UNKNOWN); bbstreamer_finalize(mystreamer->base.bbs_next);