Bug 604306 - regression: behavior of gz* functions on non-compressed empty files
Summary: regression: behavior of gz* functions on non-compressed empty files
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Fedora
Classification: Fedora
Component: zlib
Version: 13
Hardware: All
OS: Linux
low
medium
Target Milestone: ---
Assignee: Ivana Varekova
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2010-06-15 19:58 UTC by James Ralston
Modified: 2011-06-04 00:52 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2011-06-04 00:52:53 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
patch to fix regression in handling non-compressed empty files (588 bytes, patch)
2010-06-15 20:37 UTC, James Ralston
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Debian BTS 258087 0 None None None Never

Description James Ralston 2010-06-15 19:58:45 UTC
Back in 2004, the zlib maintainers fixed a bug in zlib involving the use of the (gzopen, gzgets, gzclose) functions on non-compressed empty files:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=258087

Per <http://www.zlib.net/ChangeLog.txt>, this bug was fixed upstream in zlib-1.2.1.2:

Changes in 1.2.1.2 (9 September 2004)
- Fix gzio.c to not return error on empty files [Brown]

However, sometime between 1.2.1.2 (exclusive) and 1.2.3 (inclusive), a regression occurred in zlib, and this bug was reintroduced.

Using this test program from the Debian bug:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <zlib.h>

#define BUFSIZE 80

int main() {
  int retval;
  char *input = "test", buf[BUFSIZE];
  FILE *fd;

  fd = gzopen(input, "rb");
  if (fd == NULL) {
    fprintf(stderr, "gzopen %s: %s\n", input, strerror(errno));
    exit(EXIT_FAILURE);
  }

  if(gzgets(fd, buf, BUFSIZE) == Z_NULL) {
    fprintf(stderr, "gzgets %s: %s\n", input, gzerror(fd, &retval));
  }

  retval = gzclose(fd);
  if (retval != 0) {
    if (retval != Z_ERRNO) {
      fprintf(stderr, "gzclose %s: %s\n", input, gzerror(fd, &retval));
    } else {
      perror("gzclose");
    }
    exit(EXIT_FAILURE);
  }

  return(0);
}

On RHEL4, zlib functions properly on a zero-length non-compressed file:

$ rpm -q redhat-release zlib
redhat-release-4AS-9
zlib-1.2.1.2-1.2
$ gcc -Os -Wall -pedantic -o gztest gztest.c -lz
$ rm -f test
$ touch test
$ ./gztest
gzgets test: test: stream end

But on RHEL5, it fails:

$ rpm -q redhat-release zlib
redhat-release-5Server-5.5.0.2
zlib-1.2.3-3
$ gcc -Os -Wall -pedantic -o gztest gztest.c -lz
$ rm -f test
$ touch test
$ ./gztest
gzgets test: test: buffer error
gzclose test: XX: buffer error

And on Fedora 12:

$ rpm -q fedora-release zlib
fedora-release-12-2.noarch
zlib-1.2.3-23.fc12.i686
zlib-1.2.3-23.fc12.x86_64
$ gcc -Os -Wall -pedantic -o gztest gztest.c -lz
$ rm -f test
$ touch test
$ ./gztest
gzgets test: test: buffer error
gzclose test: XX: buffer error

And on Fedora 13:

$ rpm -q fedora-release zlib
fedora-release-13-1.noarch
zlib-1.2.3-23.fc12.x86_64
zlib-1.2.3-23.fc12.i686
$ gcc -Os -Wall -pedantic -o gztest gztest.c -lz
$ rm -f test
$ touch test
$ ./gztest
gzgets test: test: buffer error
gzclose test: XXX: buffer error

However, if I compile zlib-1.2.5-1.fc14 from Rawhide, it works properly:

$ rpm -q fedora-release zlib
fedora-release-12-2.noarch
zlib-1.2.3-23.fc12.i686
zlib-1.2.5-1.fc12.x86_64
$ rm -f test
$ touch test
$ ./gztest
gzgets test: 

Per <http://www.zlib.net/>, version 1.2.4 of zlib had these improvements:

- Wholesale replacement of gz* functions with faster versions
- As part of that, added gzbuffer(), gzoffset(), gzclose_r(), and gzclose_w() functions 

So, I strongly suspect the regression was squashed (again) in version 1.2.4.

I encountered this regression the same way the Debian bug reporter encountered the original bug: I use fwlogwatch, and it is generates errors (which cron then emails to me) whenever it is run on a zero-length uncompressed file:

gzclose /var/log/messages.1: : buffer error

Given the massive dependencies on zlib, I'd be very hesitant to drop 1.2.5 as an update on F12/F13 (to say nothing of RHEL, where updating to 1.2.5 is -DNO_CHANCE). But if it is possible to fix the regression against 1.2.3 (which is what F12, F13, RHEL5, and RHEL6 all run), we should do so.

Comment 1 James Ralston 2010-06-15 20:37:50 UTC
Created attachment 424288 [details]
patch to fix regression in handling non-compressed empty files

I rebuilt zlib-1.2.3-23.fc12 using this patch from the Debian bug. The resulting zlib compiles cleanly and no longer mishandles non-compressed empty files:

$ rpm -q fedora-release zlib
fedora-release-12-2.noarch
zlib-1.2.3-23.fc12.i686
zlib-1.2.3-23.0.fc12.x86_64
$ gcc -Os -Wall -pedantic -o gztest gztest.c -lz
$ rm -f test
$ touch test
$ ./gztest 
gzgets test: test: stream end

This is the *exact* same patch that the zlib developers used to fix the bug originally.

So I think the only real question at this point is: was this regression intentional (e.g., because it was later discovered that the patch caused problems), or unintentional?

I've read through the zlib Changelog from version 1.2.1.2 through 1.2.3, but I can't see any indication why the fix was removed.

Comment 2 Bug Zapper 2011-06-02 10:42:38 UTC
This message is a reminder that Fedora 13 is nearing its end of life.
Approximately 30 (thirty) days from now Fedora will stop maintaining
and issuing updates for Fedora 13.  It is Fedora's policy to close all
bug reports from releases that are no longer maintained.  At that time
this bug will be closed as WONTFIX if it remains open with a Fedora 
'version' of '13'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version prior to Fedora 13's end of life.

Bug Reporter: Thank you for reporting this issue and we are sorry that 
we may not be able to fix it before Fedora 13 is end of life.  If you 
would still like to see this bug fixed and are able to reproduce it 
against a later version of Fedora please change the 'version' of this 
bug to the applicable version.  If you are unable to change the version, 
please add a comment here and someone will do it for you.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events.  Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

The process we are following is described here: 
http://fedoraproject.org/wiki/BugZappers/HouseKeeping

Comment 3 James Ralston 2011-06-04 00:52:53 UTC
This was never fixed for F13. And since F14 and later do not suffer from this bug, there's no reason to keep this bug open. Closing as WONTFIX.


Note You need to log in before you can comment on or make changes to this bug.