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 1uR5Zf-0066hx-77 for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Jun 2025 08:52:15 +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 1uR5Zc-00GNAn-V9 for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Jun 2025 08:52:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uR5Zc-00GNAf-Kz for pgsql-hackers@lists.postgresql.org; Mon, 16 Jun 2025 08:52:13 +0000 Received: from air.basealt.ru ([193.43.8.18]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uR5Za-002KDN-2N for pgsql-hackers@lists.postgresql.org; Mon, 16 Jun 2025 08:52:12 +0000 Received: from [192.168.1.143] (host-109-171-38-224.bbcustomer.zsttk.net [109.171.38.224]) (Authenticated sender: gorbanyoves) by air.basealt.ru (Postfix) with ESMTPSA id 7FF4F233A3; Mon, 16 Jun 2025 11:52:09 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basealt.ru; s=dkim; t=1750063929; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o4plluMgmGgJFjBPC2AZeSBKFTaprGYUL27VhfUWUq4=; b=cAbcjnZbRaC4ayb1xnrtS3Xk+HvwlzBnB4jjI1M0gIyUxagC4dwTGqhxTZzBcj369brAbF Vtza/x68lsxlZ160gJahZmygRCW2TBmPagFjc9MdzfZFROJsaNAvnrgajKieU2wvLclwWY uPyMSXLYSgTaWvI6Q6BCpI/ptY+RqI3DZSc6JfCFDoPidGlee5jUuz2sCoA78xKeWtcntn FIDv4g5+RBziCGbRoniGEAAMLhdsyAndXPsuH7Kl4TcGq0tGcg01alllYqJkPl+iy+tfVI Jv0hEBDB3OjGjCV5WlHwmM7IsjQsI6MALQyiVAKvqvU+kPB2gYayLFznTqByQw== Message-ID: <95255a86-4bc7-4ff4-aa26-4441aafdf0fb@basealt.ru> Date: Mon, 16 Jun 2025 14:52:08 +0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: No error checking when reading from file using zstd in pg_dump To: Daniel Gustafsson References: <6b9817a8-88ec-4efd-b441-9e2a0439c6b8@basealt.ru> Content-Language: en-US From: Evgeniy Gorbanev Cc: pgsql-hackers@lists.postgresql.org In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 16.06.2025 14:25, Daniel Gustafsson пишет: >> On 16 Jun 2025, at 10:14, Evgeniy Gorbanev wrote: >> In src/bin/pg_dump/compress_zstd.c, the Zstd_read function always >> returns true. But if you look at the Zstd_gets and Zstd_getc functions, >> where Zstd_read is called via CFH->read_func, it is expected that >> the Zstd_read function can also return false. In case of >> a read-from-file error, the process is expected to terminate, but >> pg_dump will continue the process. >> I assume that after checking >> if (cnt == 0) >> should be >> return false; > if (cnt == 0) > - break; > + return false; > > As cnt is coming from fread() returning false here would be wrong as you cannot > from 0 alone know if it's EOF or an error. Instead it needs to inspect the > stream with feof() and ferror() to know how to proceed. > > -- > Daniel Gustafsson The feof() check is in the calling functions, e.g. in the Zstd_getc function. Regards, Evgeniy