pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Subject: gzgetc() is hazardous to your health
Date: Sun, 19 Oct 2025 00:06:23 -0400
Message-ID: <2122679.1760846783@sss.pgh.pa.us> (raw)

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 <zlib.h> 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=mamba&dt=2025-10-17%2006%3A09%3A19
[2] https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=59711





view thread (2+ messages)  latest in thread

Message-ID: <2122679.1760846783@sss.pgh.pa.us>
Permalink:  ../2122679.1760846783@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2122679.1760846783@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: gzgetc() is hazardous to your health
  In-Reply-To: <2122679.1760846783@sss.pgh.pa.us>
  References: <2122679.1760846783@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox