Re: No error checking when reading from file using zstd in pg_dump
Daniel Gustafsson <daniel@yesql.se>
From: Daniel Gustafsson <daniel@yesql.se>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Evgeniy Gorbanev <gorbanyoves@basealt.ru>,
pgsql-hackers@lists.postgresql.org
Date: 2025-06-16T14:11:58Z
Lists: 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
Commits
-
pg_dump: Fix compression API errorhandling
- ec017a305bd4 16.11 landed
- e686010c5b47 19 (unreleased) landed
- 92268b35d04c 17.7 landed
- 8980c724b559 18.0 landed