commit f5cec129347c3ef65df791e0693bd7029f895591
Author: Daniel Gustafsson <dgustafsson@postgresql.org>
Date:   Tue Aug 11 21:34:32 2026 +0200

    wip

diff --git a/src/bin/pg_dump/compress_lz4.c b/src/bin/pg_dump/compress_lz4.c
index 500d5e16a6d..29599773abb 100644
--- a/src/bin/pg_dump/compress_lz4.c
+++ b/src/bin/pg_dump/compress_lz4.c
@@ -193,6 +193,9 @@ ReadDataFromArchiveLZ4(ArchiveHandle *AH, CompressorState *cs)
 		}
 	}
 
+	if (status != 0)
+		pg_fatal("could not decompress: chunk is incomplete");
+
 	pg_free(outbuf);
 	pg_free(readbuf);
 
diff --git a/src/bin/pg_dump/compress_zstd.c b/src/bin/pg_dump/compress_zstd.c
index 68f1d815917..4ef4ce58746 100644
--- a/src/bin/pg_dump/compress_zstd.c
+++ b/src/bin/pg_dump/compress_zstd.c
@@ -203,6 +203,24 @@ ReadDataFromArchiveZstd(ArchiveHandle *AH, CompressorState *cs)
 			if (res == 0)
 				break;			/* End of frame */
 		}
+
+		/*
+		 * If ZSTD_decompressStream returned non-zero when all input was
+		 * consumed then there is data left buffered, drain any remaining data
+		 * by calling decompression again with an empty input.
+		 */
+		if (res > 0)
+		{
+			ZSTD_inBuffer empty = {NULL, 0, 0};
+
+			output->pos = 0;
+
+			res = ZSTD_decompressStream(zstdcs->dstream, output, &empty);
+			if (ZSTD_isError(res))
+				pg_fatal("1 could not decompress data: %s", ZSTD_getErrorName(res));
+			((char *) output->dst)[output->pos] = '\0';
+			ahwrite(output->dst, 1, output->pos, AH);
+		}
 	}
 }
 
