Bug 440551

Summary: file -k behaviour broken since 4.4
Product: Red Hat Enterprise Linux 4 Reporter: Bryan Mason <nobody+bjmason>
Component: fileAssignee: Daniel Novotny <dnovotny>
Status: CLOSED ERRATA QA Contact:
Severity: high Docs Contact:
Priority: high    
Version: 4.6CC: bmason, ksrot, rvokal, tao
Target Milestone: rcKeywords: Regression
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-05-18 20:06:09 UTC Type: ---
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: 391511    
Attachments:
Description Flags
Example test file.
none
Proposed patch. none

Description Bryan Mason 2008-04-03 23:02:38 UTC
Description of problem:

    Running "file -k <file.tgz>" doesn't emit extra output.

Version-Release number of selected component (if applicable):

    file-4.10-3.0.2.el4.i386

How reproducible:

    Always.

Steps to Reproduce:

    1.  Download attached file, for example.
    2.  file -k /path/to/broken-file.tgz
  
Actual results:

    /tmp/broken-file.tgz: FLI file - 18355 frames, width=768 pixels,
    height=15852 pixels, depth=30717, ticks/frame=64434\012

Expected results:

    /tmp/broken-file.tgz: FLI file - 18355 frames, width=768 pixels, 
    height=15852 pixels, depth=30717, ticks/frame=64434\012- gzip compressed 
    data, from Unix

Additional info:

    Proposed patch will be attached.

Comment 1 Bryan Mason 2008-04-03 23:02:38 UTC
Created attachment 300362 [details]
Example test file.

Comment 2 Bryan Mason 2008-04-03 23:03:40 UTC
Created attachment 300363 [details]
Proposed patch.

Comment 3 Bryan Mason 2008-04-03 23:16:49 UTC
This is actually a regression induced by the fix to Bug 174348.  

The important bit of code in the patch that fixed that bug is here:

   while (n > 0) {
            bytesconsumed = mbrtowc(&nextchar, op, n, &state);
            if (bytesconsumed == (size_t)(-1) ||
                            bytesconsumed == (size_t)(-2)) {
                    mb_conv = 0;
                    break;
            }

            if (iswprint (nextchar) ){
                    memcpy (np, op, bytesconsumed);
                    op += bytesconsumed;
            } else {
                    *np++ = '\\';
                    *np++ = ((*op >> 6) & 3) + '0';
                    *np++ = ((*op >> 3) & 7) + '0';
                    *np++ = ((*op >> 0) & 7) + '0';
                    op++;
            }
            np += bytesconsumed;
            n -= bytesconsumed;
    }
    *np = '\0';

np is getting double-incremented whenever the loop comes across a non-printable
character.  It gets incremented during the conversion of the non-printable
character to it's octal representation:

            } else {
                    *np++ = '\\';
                    *np++ = ((*op >> 6) & 3) + '0';
                    *np++ = ((*op >> 3) & 7) + '0';
                    *np++ = ((*op >> 0) & 7) + '0';
                    op++;
            }

and then again at the bottom of the loop:

            np += bytesconsumed;

Since np gets incremented twice, an uninitialized value (which I supposed
happens to be zero most of the time) gets left in the buffer, truncating the
buffer when it gets printed.

The proposed patch moves "np += bytesconsumed" inside "if (iswprint (nextchar) ){"

Comment 4 RHEL Program Management 2008-04-03 23:23:34 UTC
This bugzilla has Keywords: Regression.  

Since no regressions are allowed between releases, 
it is also being proposed as a blocker for this release.  

Please resolve ASAP.

Comment 6 Daniel Novotny 2008-09-18 16:11:02 UTC
the patch works, thanks. we can use it in the next release.

Comment 9 Daniel Novotny 2008-10-22 10:21:16 UTC
fixed in file-4.10-6.el4

Comment 14 errata-xmlrpc 2009-05-18 20:06:09 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2009-0954.html