Opened 11 years ago

Closed 6 years ago

Last modified 6 years ago

#5908 closed Bugs (fixed)

iostreams gzip fails to handle optional extra fields in gzip header

Reported by: Travis Abbott <typedef.struct@…> Owned by: Jonathan Turkanis
Milestone: To Be Determined Component: iostreams
Version: Boost 1.47.0 Severity: Problem
Keywords: gzip Cc:

Description

When bit 2 (FEXTRA) is set in a gzip header's flags, the iostreams code fails to read the XLEN field before starting to read the extra comment. The code is actually there to do it, but it gets skipped. This means the code goes directly a loop like: while (--xlen != 0) with xlen still set to 0. This results in the rest of the file being slurped in by this comment reading code (or at least until xlen wraps around to 0 again, which could take awhile). I ran into this because many popular file formats in bioinformatics (BAM, tabix) are gzipped and include extra optional fields in their headers.

I've attached an example gzipped file with an optional header, a test program that should demonstrate the problem (against 1.47 and latest svn), as well as a patch that fixes it.

Attachments (4)

sample.txt.gz (68 bytes ) - added by Travis Abbott <typedef.struct@…> 11 years ago.
gzip file with extra comment in header
example.cpp (733 bytes ) - added by Travis Abbott <typedef.struct@…> 11 years ago.
test case that demonstrates the problem (run ./example sample.txt.gz)
iostreams-gzip.patch (493 bytes ) - added by Travis Abbott <typedef.struct@…> 11 years ago.
patch that fixes the issue (patch -p0 < iostreams-gzip.patch from top level of the repo)
iostreams-gzip_hdr_test.patch (2.4 KB ) - added by typedef.struct@… 11 years ago.
second patch adding unit test to prevent future regressions.

Download all attachments as: .zip

Change History (12)

by Travis Abbott <typedef.struct@…>, 11 years ago

Attachment: sample.txt.gz added

gzip file with extra comment in header

by Travis Abbott <typedef.struct@…>, 11 years ago

Attachment: example.cpp added

test case that demonstrates the problem (run ./example sample.txt.gz)

by Travis Abbott <typedef.struct@…>, 11 years ago

Attachment: iostreams-gzip.patch added

patch that fixes the issue (patch -p0 < iostreams-gzip.patch from top level of the repo)

comment:1 by typedef.struct@…, 11 years ago

Seems like this is still present in 1.48 and current SVN. To be clear, the sample file is not empty. The desired output would be for the test program to read "hello there", but it gets nothing. You can compare to gzip -dc. The supplied patch still works with current SVN.

comment:2 by typedef.struct@…, 11 years ago

Also worth mentioning is that this worked in 1.40, but when the ability to support multiple compressed objects in 1 gzipped stream was introduced, this bug appeared.

by typedef.struct@…, 11 years ago

second patch adding unit test to prevent future regressions.

comment:3 by typedef.struct@…, 11 years ago

The test attached in the second patch (iostreams-gzip_hdr_test.patch) will fail with the current code, demonstrating the inability to parse certain types of RFC 1952 compliant gzip headers. Application of the first patch will cause the test to pass.

comment:4 by Jonathan Turkanis, 11 years ago

Status: newassigned

I have applied the patches to trunk.

comment:5 by Daniel James, 11 years ago

Resolution: fixed
Status: assignedclosed

(In [77368]) Iostreams: Merge from trunk.

comment:6 by Smithc195, 6 years ago

Component: iostreamsxpressive
Milestone: To Be DeterminedWebsite 1.X
Resolution: fixed
Severity: ProblemNot Applicable
Status: closedreopened
Type: BugsLibrary Submissions
Version: Boost 1.47.0Boost.Build-M3

Hi. Only wanted to ask a quick issue. Now i am eaadkebdkckdgfgd

comment:7 by Daniel James, 6 years ago

Resolution: fixed
Status: reopenedclosed

comment:8 by Kohei Takahashi, 6 years ago

Component: xpressiveiostreams
Milestone: Website 1.XTo Be Determined
Severity: Not ApplicableProblem
Type: Library SubmissionsBugs
Version: Boost.Build-M3Boost 1.47.0
Note: See TracTickets for help on using tickets.