Bug 2095828

Summary: file -z prints incorrect messages when handling zlib compressed files
Product: Red Hat Enterprise Linux 8 Reporter: Paulo Andrade <pandrade>
Component: fileAssignee: Vincent Mihalkovič <vmihalko>
Status: CLOSED ERRATA QA Contact: Karel Volný <kvolny>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 8.6CC: kdudka, kvolny, lzaoral, sujagtap
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: file-5.33-21.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2121694 (view as bug list) Environment:
Last Closed: 2022-11-08 10:56:50 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2121694    

Description Paulo Andrade 2022-06-10 16:55:39 UTC
=== Steps to reproduce ===

$ touch a b
$ zip x a b
$ file -z x.zip
x.zip: ERROR:[gzip: Stdin has more than one entry--rest ignored] (Zip archive data, at least v1.0 to extract, compression method=store)

$ rm a b x.zip

$ mkdir x
$ touch x/{a,b}
$ zip x x
  adding: x/ (stored 0%)
$ file -z x.zip 
x.zip: ERROR:[gzip: Read failed, No such file or directory] (Zip archive data, at least v1.0 to extract, compression method=store)

===

  The root cause is due to the uncompressbuf method, in rhel7
(https://github.com/file/file/blob/FILE5_11/src/compress.c)

"""
		if ((r = sread(fdout[0], *newch, HOWMANY, 0)) <= 0) {
#ifdef DEBUG
			(void)fprintf(stderr, "Read failed (%s)\n",
			    strerror(errno));
#endif
			free(*newch);
			n = 0;
			newch[0] = '\0';
			goto err;
		} else {
			n = r;
		}
 		/* NUL terminate, as every buffer is handled here. */
"""

and in rhel8 the code is:
(https://github.com/file/file/blob/FILE5_33/src/compress.c)

"""
		if ((r = sread(fdp[STDOUT_FILENO][0], *newch, bytes_max, 0)) > 0)
			break;
		DPRINTF("Read stdout failed %d (%s)\n", fdp[STDOUT_FILENO][0],
		    r != -1 ? strerror(errno) : "no data");

		rv = ERRDATA;
		if (r == 0 &&
		    (r = sread(fdp[STDERR_FILENO][0], *newch, bytes_max, 0)) > 0)
		{
			r = filter_error(*newch, r);
			break;
		}
		free(*newch);
		if  (r == 0)
			rv = makeerror(newch, n, "Read failed, %s",
			    strerror(errno));
"""

  The gzip messages should be printed to stderr, and better if only
when "-d" is passed, to print debug messages.

Comment 19 errata-xmlrpc 2022-11-08 10:56:50 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (file bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:7808