NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/59711: "#define HAVE_UNISTD_H 1" breaks 32-bit libz



>Number:         59711
>Category:       lib
>Synopsis:       "#define HAVE_UNISTD_H 1" breaks 32-bit libz
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Oct 19 03:05:00 +0000 2025
>Originator:     Tom Lane
>Release:        10.1
>Organization:
>Environment:
NetBSD g42.sss.pgh.pa.us 10.1 NetBSD 10.1 (GENERIC) #0: Mon Dec 16 13:08:11 UTC 2024  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/macppc/compile/GENERIC macppc
>Description:
If HAVE_UNISTD_H is defined in an application that #include's <zlib.h>, then z_off_t becomes defined as off_t (hence, 64 bits pretty much everywhere).  Otherwise, it becomes defined as "long" (hence, not so predictable).  Furthermore, unless something is done to cause Z_LARGE64 to become defined, z_off64_t is defined as z_off_t, hence it's not reliably 64 bits after all.

This is problematic on macppc because libz.so is evidently built with the 32-bit definition.  If the application defines HAVE_UNISTD_H, then the gzgetc() macro will think that gzFile_s.pos is 64 bits while the library thinks it's 32, leading to hilarity.

I initially thought that this was generic to 32-bit platforms, but I failed to reproduce the bug on NetBSD 10.0 evbarm, so maybe there's something macppc-specific here.  I have not dug into the build recipe for libz.
>How-To-Repeat:
A caller that alternates between gzread() and gzgetc() calls hits a failure immediately.  I have a test program that is perhaps slightly too long to paste into this webform, so I'll email it as a followup.
>Fix:
Seems like a mess: you'll have an ABI break whichever way you jump.  But it seems like the place to end up is that the field is 64 bits for everybody.

FWIW, looking at <zconf.h> on a Red Hat platform, it looks like they stabilized things by changing

#ifdef HAVE_UNISTD_H    /* may be set to #if 1 by ./configure */
#  define Z_HAVE_UNISTD_H
#endif

#ifdef HAVE_STDARG_H    /* may be set to #if 1 by ./configure */
#  define Z_HAVE_STDARG_H
#endif

to "#if 1" for each.



Home | Main Index | Thread Index | Old Index