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 1vAKgh-00HALy-Dk for pgsql-hackers@arkaria.postgresql.org; Sun, 19 Oct 2025 04:06:30 +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 1vAKge-009wjv-F5 for pgsql-hackers@arkaria.postgresql.org; Sun, 19 Oct 2025 04:06:27 +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 1vAKge-009wjm-5A for pgsql-hackers@lists.postgresql.org; Sun, 19 Oct 2025 04:06:27 +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 1vAKga-002Yc3-2e for pgsql-hackers@lists.postgresql.org; Sun, 19 Oct 2025 04:06:26 +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 59J46N1J2122680 for ; Sun, 19 Oct 2025 00:06:23 -0400 From: Tom Lane To: pgsql-hackers@lists.postgresql.org Subject: gzgetc() is hazardous to your health MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2122678.1760846783.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 19 Oct 2025 00:06:23 -0400 Message-ID: <2122679.1760846783@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk In the gift-that-keeps-on-giving department: I noticed a few days ago while fooling with pg_dump's compression logic that our regression tests were not reaching any of the getc_func methods. It turns out that that's only used when reading a manually-compressed TOC file in a directory-format dump, and we were not exercising that case. That oversight already allowed one undetected bug (cf a239c4a0c), so I put in 20ec99589 ... and mamba promptly fell over [1]. After a couple of hours of digging I found that there's a configuration-sensitive bug in NetBSD's 32-bit build of zlib [2]: if HAVE_UNISTD_H is defined before including then the gzgetc() macro ends up thinking that gzFile_s.pos is 64 bits, while the library thinks it's 32. Ooops. This can't be blamed entirely on NetBSD: zconf.h is hoary old code that tries to deal with a lot of not-very-consistent platforms. I think it likely that other platforms have similar issues, which we'd not notice given that (a) we haven't been testing this case and (b) probably few users are invoking it either and (c) it probably only fails on 32-bit platforms. What I think we ought to do about this is get rid of our one usage of gzgetc(), replacing it with a one-byte gzread() operation. That's not lovely from a speed perspective, but I don't think that reading a pg_dump TOC file is really speed-critical. regards, tom lane PS: I've temporarily disabled --enable-tap-tests on mamba so that it will go back to green. That's hardly a fix though. [1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=3Dmamba&dt=3D2= 025-10-17%2006%3A09%3A19 [2] https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=3D59711