Re: No error checking when reading from file using zstd in pg_dump - Mailing list pgsql-hackers

From Daniel Gustafsson
Subject Re: No error checking when reading from file using zstd in pg_dump
Date
Msg-id 3815B6CD-924B-40FA-823A-55E2F8F24602@yesql.se
Whole thread Raw
In response to Re: No error checking when reading from file using zstd in pg_dump  (Evgeniy Gorbanev <gorbanyoves@basealt.ru>)
List pgsql-hackers
> On 16 Jun 2025, at 15:56, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> I've not checked to see what the other users of this API do, but
> if they're all like this then we need to fix that comment.

AFAICT all other callers of this API are throwing an error with pg_fatal, and
so does the function in question for ZStd decompression errors.  If we handle
the case of fread() returning 0 to indicate an error like the below *untested
sketch* (with a better error message) this function is fully API compliant as
well.

                /* If we have no more input to consume, we're done */
                if (cnt == 0)
+               {
+                       if (ferror(unconstify(void *, input->src)))
+                               pg_fatal("could not read data to decompress: %m");
+
                        break;
+               }

If this seems like a good approach then Zstd_getc can be simplified as well as
it no longer needs to call ferror, it still needs to check feof though.

--
Daniel Gustafsson




pgsql-hackers by date:

Previous
From: Yugo Nagata
Date:
Subject: Re: relrewrite not documented at the top of heap_create_with_catalog()
Next
From: Andres Freund
Date:
Subject: Re: Read-Write optimistic lock (Re: sinvaladt.c: remove msgnumLock, use atomic operations on maxMsgNum)