Skip to content

Commit 33276cd

Browse files
committed
Don't rely on zlib's gzgetc() macro.
It emerges that zlib's configuration logic is not robust enough to guarantee that the macro will have the same ideas about struct field layout as the library itself does, leading to corruption of zlib's state struct followed by unintelligible failure messages. This hazard has existed for a long time, but we'd not noticed for several reasons: (1) We only use gzgetc() when trying to read a manually-compressed TOC file within a directory-format dump, which is a rarely-used scenario that we weren't even testing before 20ec995. (2) No corruption actually occurs unless sizeof(long) is different from sizeof(off_t) and the platform is big-endian. (3) Some platforms have already fixed the configuration instability, at least sufficiently for their environments. Despite (3), it seems foolish to assume that the problem isn't going to be present in some environments for a long time to come. Hence, avoid relying on this macro. We can just #undef it and fall back on the underlying function of the same name. Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/2122679.1760846783@sss.pgh.pa.us Backpatch-through: 13
1 parent d20df95 commit 33276cd

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@
3838
*/
3939
#ifdef HAVE_LIBZ
4040
#include <zlib.h>
41+
42+
/*
43+
* We don't use the gzgetc() macro, because zlib's configuration logic is not
44+
* robust enough to guarantee that the macro will have the same ideas about
45+
* struct field layout as the library itself does; see for example
46+
* https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=59711
47+
* Instead, #undef the macro and fall back to the underlying function.
48+
*/
49+
#undef gzgetc
50+
4151
#define GZCLOSE(fh) gzclose(fh)
4252
#define GZWRITE(p, s, n, fh) gzwrite(fh, p, (n) * (s))
4353
#define GZREAD(p, s, n, fh) gzread(fh, p, (n) * (s))

0 commit comments

Comments
 (0)