Bug 440551 - file -k behaviour broken since 4.4
Summary: file -k behaviour broken since 4.4
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: file   
(Show other bugs)
Version: 4.6
Hardware: All
OS: Linux
high
high
Target Milestone: rc
: ---
Assignee: Daniel Novotny
QA Contact:
URL:
Whiteboard:
Keywords: Regression
Depends On:
Blocks: 391511
TreeView+ depends on / blocked
 
Reported: 2008-04-03 23:02 UTC by Bryan Mason
Modified: 2010-05-12 12:17 UTC (History)
4 users (show)

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: ---


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


External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2009:0954 normal SHIPPED_LIVE file bug fix update 2009-05-18 13:23:50 UTC

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 Product and 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


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