[jira] [Commented] (COMPRESS-84) GZip corrupt files are partially unzipped

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (COMPRESS-84) GZip corrupt files are partially unzipped

ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/COMPRESS-84?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13088175#comment-13088175 ]

Lasse Collin commented on COMPRESS-84:
--------------------------------------

The test program is buggy. It tests for cis.read() > 0 instead of >= 0. If the input is corrupt, cis.read() may return many corrupt bytes before detecting an error. So cis.read() may return 0 even if the original file was a text file.

> GZip corrupt files are partially unzipped
> -----------------------------------------
>
>                 Key: COMPRESS-84
>                 URL: https://issues.apache.org/jira/browse/COMPRESS-84
>             Project: Commons Compress
>          Issue Type: Bug
>          Components: Compressors
>    Affects Versions: 1.0
>         Environment: Apache Maven 2.2.0 (r788681; 2009-06-26 15:04:01+0200)
> Java version: 1.6.0_14
> Java home: /opt/jdk1.6.0_14/jre
> Default locale: fr_FR, platform encoding: UTF-8
> OS name: "linux" version: "2.6.30.5-28.rc2.fc11.i586" arch: "i386" Family: "unix"
> In POM : {noformat}
> <dependency>
> <groupId>org.apache.commons</groupId>
> <artifactId>commons-compress</artifactId>
> <version>1.0</version>
> <type>jar</type>
> <scope>compile</scope>
> </dependency>{noformat}
>            Reporter: Florent Charton
>
> While trying to decompres gzipped data with random removed bytes, no exceptions are thrown. Same file with zcat command line utility produces error below
> {noformat}gzip: badfiles-red-64/data.txt.gz: invalid compressed data--crc error
> gzip: badfiles-red-64/data.txt.gz: invalid compressed data--length error
> {noformat}
> The code below should throw an exception about corrupted file
> {code:title=Sample extraction code}
>         CompressorInputStream cis = null;
>         try {
>             cis = new CompressorStreamFactory().createCompressorInputStream(
>                     "gz", new FileInputStream("badfiles-red-64/data.txt.gz"));
>         } catch (CompressorException e) {
>             // This will never happen unless "gz" is changed 2 lines above
>             log.error(e.getMessage(), e);
>             throw new ProcessingException(e);
>         }
>         try {
>             while (cis.read() > 0) {
>             }
>         } catch (IOException e) {
>             log.error(e.getMessage(), e);
>             throw new ProcessingException(e);
>         }
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira