]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Exit after fatal errors in client-side compression code.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 5 Mar 2026 19:43:21 +0000 (14:43 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 5 Mar 2026 19:43:21 +0000 (14:43 -0500)
It looks like whoever wrote the astreamer (nee bbstreamer) code
thought that pg_log_error() is equivalent to elog(ERROR), but
it's not; it just prints a message.  So all these places tried to
continue on after a compression or decompression error return,
with the inevitable result being garbage output and possibly
cascading error messages.  We should use pg_fatal() instead.

These error conditions are probably pretty unlikely in practice,
which no doubt accounts for the lack of field complaints.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/1531718.1772644615@sss.pgh.pa.us
Backpatch-through: 15

src/bin/pg_basebackup/bbstreamer_gzip.c
src/bin/pg_basebackup/bbstreamer_lz4.c
src/bin/pg_basebackup/bbstreamer_zstd.c

index c3455ffbddf88f8195bc69ecf3edfd7ed5079ecd..4bfb9e77b9b2282bea43280409f6ba0a59507aaf 100644 (file)
@@ -293,7 +293,7 @@ bbstreamer_gzip_decompressor_content(bbstreamer *streamer,
                res = inflate(zs, Z_NO_FLUSH);
 
                if (res == Z_STREAM_ERROR)
-                       pg_log_error("could not decompress data: %s", zs->msg);
+                       pg_fatal("could not decompress data: %s", zs->msg);
 
                mystreamer->bytes_written =
                        mystreamer->base.bbs_buffer.maxlen - zs->avail_out;
index 6f583cb41686f48546c799dfe144334ecf87bdd4..043bbb0cfe16d882780966751ca0047b3e6142a1 100644 (file)
@@ -92,8 +92,8 @@ bbstreamer_lz4_compressor_new(bbstreamer *next, pg_compress_specification *compr
 
        ctxError = LZ4F_createCompressionContext(&streamer->cctx, LZ4F_VERSION);
        if (LZ4F_isError(ctxError))
-               pg_log_error("could not create lz4 compression context: %s",
-                                        LZ4F_getErrorName(ctxError));
+               pg_fatal("could not create lz4 compression context: %s",
+                                LZ4F_getErrorName(ctxError));
 
        return &streamer->base;
 #else
@@ -137,8 +137,8 @@ bbstreamer_lz4_compressor_content(bbstreamer *streamer,
                                                                                         &mystreamer->prefs);
 
                if (LZ4F_isError(compressed_size))
-                       pg_log_error("could not write lz4 header: %s",
-                                                LZ4F_getErrorName(compressed_size));
+                       pg_fatal("could not write lz4 header: %s",
+                                        LZ4F_getErrorName(compressed_size));
 
                mystreamer->bytes_written += compressed_size;
                mystreamer->header_written = true;
@@ -186,8 +186,8 @@ bbstreamer_lz4_compressor_content(bbstreamer *streamer,
                                                                                  next_in, len, NULL);
 
        if (LZ4F_isError(compressed_size))
-               pg_log_error("could not compress data: %s",
-                                        LZ4F_getErrorName(compressed_size));
+               pg_fatal("could not compress data: %s",
+                                LZ4F_getErrorName(compressed_size));
 
        mystreamer->bytes_written += compressed_size;
 }
@@ -238,8 +238,8 @@ bbstreamer_lz4_compressor_finalize(bbstreamer *streamer)
                                                                           next_out, avail_out, NULL);
 
        if (LZ4F_isError(compressed_size))
-               pg_log_error("could not end lz4 compression: %s",
-                                        LZ4F_getErrorName(compressed_size));
+               pg_fatal("could not end lz4 compression: %s",
+                                LZ4F_getErrorName(compressed_size));
 
        mystreamer->bytes_written += compressed_size;
 
@@ -351,8 +351,8 @@ bbstreamer_lz4_decompressor_content(bbstreamer *streamer,
                                                          next_in, &read_size, NULL);
 
                if (LZ4F_isError(ret))
-                       pg_log_error("could not decompress data: %s",
-                                                LZ4F_getErrorName(ret));
+                       pg_fatal("could not decompress data: %s",
+                                        LZ4F_getErrorName(ret));
 
                /* Update input buffer based on number of bytes consumed */
                avail_in -= read_size;
index 1207dd771ae55bc0a2b949d520029c4bd7cf67d4..02f5db77c2dcab01c5380c191779700cae2ab9af 100644 (file)
@@ -165,8 +165,8 @@ bbstreamer_zstd_compressor_content(bbstreamer *streamer,
                                                                 &inBuf, ZSTD_e_continue);
 
                if (ZSTD_isError(yet_to_flush))
-                       pg_log_error("could not compress data: %s",
-                                                ZSTD_getErrorName(yet_to_flush));
+                       pg_fatal("could not compress data: %s",
+                                        ZSTD_getErrorName(yet_to_flush));
        }
 }
 
@@ -207,8 +207,8 @@ bbstreamer_zstd_compressor_finalize(bbstreamer *streamer)
                                                                                        &in, ZSTD_e_end);
 
                if (ZSTD_isError(yet_to_flush))
-                       pg_log_error("could not compress data: %s",
-                                                ZSTD_getErrorName(yet_to_flush));
+                       pg_fatal("could not compress data: %s",
+                                        ZSTD_getErrorName(yet_to_flush));
 
        } while (yet_to_flush > 0);
 
@@ -313,8 +313,8 @@ bbstreamer_zstd_decompressor_content(bbstreamer *streamer,
                                                                        &mystreamer->zstd_outBuf, &inBuf);
 
                if (ZSTD_isError(ret))
-                       pg_log_error("could not decompress data: %s",
-                                                ZSTD_getErrorName(ret));
+                       pg_fatal("could not decompress data: %s",
+                                        ZSTD_getErrorName(ret));
        }
 }