Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uRAh3-007q5b-8A for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Jun 2025 14:20:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uRAh1-000btW-5N for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Jun 2025 14:20:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uRAh0-000btF-S3 for pgsql-hackers@lists.postgresql.org; Mon, 16 Jun 2025 14:20:11 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uRAgz-002KTM-2p for pgsql-hackers@lists.postgresql.org; Mon, 16 Jun 2025 14:20:10 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 55GEK7fw520143; Mon, 16 Jun 2025 10:20:07 -0400 From: Tom Lane To: Daniel Gustafsson cc: Evgeniy Gorbanev , pgsql-hackers@lists.postgresql.org Subject: Re: No error checking when reading from file using zstd in pg_dump In-reply-to: <3815B6CD-924B-40FA-823A-55E2F8F24602@yesql.se> References: <6b9817a8-88ec-4efd-b441-9e2a0439c6b8@basealt.ru> <95255a86-4bc7-4ff4-aa26-4441aafdf0fb@basealt.ru> <522DB522-3962-4F91-A691-2DE790F6CCD6@yesql.se> <517794.1750082166@sss.pgh.pa.us> <3815B6CD-924B-40FA-823A-55E2F8F24602@yesql.se> Comments: In-reply-to Daniel Gustafsson message dated "Mon, 16 Jun 2025 16:11:58 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <520141.1750083607.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 16 Jun 2025 10:20:07 -0400 Message-ID: <520142.1750083607@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Daniel Gustafsson writes: >> On 16 Jun 2025, at 15:56, Tom Lane 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. I think I agree that we need to handle the ferror() case inside the read_func for consistency. But there is another problem, which is that neither of its callers are paying attention to the API: as defined, the read_func can never return anything but "true", which is how Zstd_read behaves. But both the callers in compress_zstd.c seem to think they should test its result to detect EOF. Apparently, our tests do not cover the case of an unexpected EOF. This API is actually quite bizarrely defined, if you ask me. Returning the byte count is optional, but if you don't pay attention to the byte count you cannot know if you got any data. At best, that's bug-encouraging. regards, tom lane