From 9db03ce247ef7b1f3d3f057bab3c8ec6ec7ac74f Mon Sep 17 00:00:00 2001 From: "Chao Li (Evan)" Date: Mon, 10 Aug 2026 14:39:34 +0800 Subject: [PATCH v2 2/2] Fix detection of truncated gzip-compressed backups astreamer_gzip_decompressor did not check whether inflate() had reached Z_STREAM_END before finalizing. As a result, pg_verifybackup could accept a truncated gzip-compressed tar backup. Record whether inflate() completed the gzip stream, and reject finalization if it did not. Author: Chao Li Reviewed-by: Discussion: https://postgr.es/m/5962B878-C43D-4EBC-9E95-1F945CE5E586@gmail.com --- src/fe_utils/astreamer_gzip.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/fe_utils/astreamer_gzip.c b/src/fe_utils/astreamer_gzip.c index bc3d53076e1..1cb6b9800d3 100644 --- a/src/fe_utils/astreamer_gzip.c +++ b/src/fe_utils/astreamer_gzip.c @@ -48,6 +48,7 @@ typedef struct astreamer_gzip_decompressor astreamer base; z_stream zstream; size_t bytes_written; + bool stream_finished; } astreamer_gzip_decompressor; static void astreamer_gzip_writer_content(astreamer *streamer, @@ -322,6 +323,8 @@ astreamer_gzip_decompressor_content(astreamer *streamer, pg_fatal("could not decompress data: %s", zs->msg ? zs->msg : "unknown error"); + mystreamer->stream_finished = (res == Z_STREAM_END); + mystreamer->bytes_written = mystreamer->base.bbs_buffer.maxlen - zs->avail_out; @@ -346,6 +349,9 @@ astreamer_gzip_decompressor_finalize(astreamer *streamer) mystreamer = (astreamer_gzip_decompressor *) streamer; + if (!mystreamer->stream_finished) + pg_fatal("could not decompress data: compressed stream is incomplete"); + /* * End of the stream, if there is some pending data in output buffers then * we must forward it to next streamer. -- 2.50.1 (Apple Git-155)