postgres.git / summary / log / commit / refs
commit 78dc9a808201b06a59f2bfb03018f790a5fc15ba
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Wed Mar 04 17:08:37 2026 +0000
First released in: 19.0, 15.18, 16.14, 17.10, 18.4
Fix yet another bug in archive streamer with LZ4 decompression.
The code path in astreamer_lz4_decompressor_content() that updated
the output pointers when the output buffer isn't full was wrong.
It advanced next_out by bytes_written, which could include previous
decompression output not just that of the current cycle. The
correct amount to advance is out_size. While at it, make the
output pointer updates look more like the input pointer updates.
This bug is pretty hard to reach, as it requires consecutive
compression frames that are too small to fill the output buffer.
pg_dump could have produced such data before 66ec01dc4, but
I'm unsure whether any files we use astreamer with would be
likely to contain problematic data.
Author: Chao Li <lic@highgo.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/0594CC79-1544-45DD-8AA4-26270DE777A7@gmail.com
Backpatch-through: 15
src/fe_utils/astreamer_lz4.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/src/fe_utils/astreamer_lz4.c b/src/fe_utils/astreamer_lz4.c
index 5f581d1de37..12ddecbe71e 100644
--- a/src/fe_utils/astreamer_lz4.c
+++ b/src/fe_utils/astreamer_lz4.c
@@ -360,11 +360,14 @@ astreamer_lz4_decompressor_content(astreamer *streamer,
avail_in -= read_size;
next_in += read_size;
+ /* Update output buffer based on number of bytes produced */
+ avail_out -= out_size;
+ next_out += out_size;
mystreamer->bytes_written += out_size;
/*
* If output buffer is full then forward the content to next streamer
- * and update the output buffer.
+ * and reset the output buffer.
*/
if (mystreamer->bytes_written >= mystreamer->base.bbs_buffer.maxlen)
{
@@ -374,13 +377,8 @@ astreamer_lz4_decompressor_content(astreamer *streamer,
context);
avail_out = mystreamer->base.bbs_buffer.maxlen;
- mystreamer->bytes_written = 0;
next_out = (uint8 *) mystreamer->base.bbs_buffer.data;
- }
- else
- {
- avail_out = mystreamer->base.bbs_buffer.maxlen - mystreamer->bytes_written;
- next_out += mystreamer->bytes_written;
+ mystreamer->bytes_written = 0;
}
}
}
[parent: e2ee58eec079]