Bug 440551 - file -k behaviour broken since 4.4
file -k behaviour broken since 4.4
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: file (Show other bugs)
4.6
All Linux
high Severity high
: rc
: ---
Assigned To: Daniel Novotny
: Regression
Depends On:
Blocks: 391511
  Show dependency treegraph
 
Reported: 2008-04-03 19:02 EDT by Bryan Mason
Modified: 2010-05-12 08:17 EDT (History)
4 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2009-05-18 16:06:09 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Example test file. (32 bytes, application/x-compressed-tar)
2008-04-03 19:02 EDT, Bryan Mason
no flags Details
Proposed patch. (616 bytes, patch)
2008-04-03 19:03 EDT, Bryan Mason
no flags Details | Diff

  None (edit)
Description Bryan Mason 2008-04-03 19:02:38 EDT
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 19:02:38 EDT
Created attachment 300362 [details]
Example test file.
Comment 2 Bryan Mason 2008-04-03 19:03:40 EDT
Created attachment 300363 [details]
Proposed patch.
Comment 3 Bryan Mason 2008-04-03 19:16:49 EDT
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 Product and Program Management 2008-04-03 19:23:34 EDT
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 12:11:02 EDT
the patch works, thanks. we can use it in the next release.
Comment 9 Daniel Novotny 2008-10-22 06:21:16 EDT
fixed in file-4.10-6.el4
Comment 14 errata-xmlrpc 2009-05-18 16:06:09 EDT
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

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