ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 45836] New: [PATCH] For correct empty CBzip2OutputStream handling
Date Thu, 18 Sep 2008 18:09:07 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=45836

           Summary: [PATCH] For correct empty CBzip2OutputStream handling
           Product: Ant
           Version: 1.8Alpha (nightly)
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Other
        AssignedTo: notifications@ant.apache.org
        ReportedBy: tommay@google.com


Created an attachment (id=22604)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=22604)
Patch to fix empty CBzip2OutputStream

In 1.7.1, creating and then closing a CBzip2OutputStream without writing any
dya to it would incorrectly result in an ArithmeticException being thrown (bug
32200).  The code in svn has been modified so this no longer happens.  However,
the resulting compressed output is no longer valid and won't decompress with
bunzip2 after prepending "BZ" to the stream.

Here's a patch against the code in svn that fixes the problem correctly as far
as I can tell.

Here's a test program:

$ cat X.java
import org.apache.tools.bzip2.CBZip2OutputStream;

class X {
    public static void main(String[] args) throws Exception {
        new CBZip2OutputStream(System.out).close();
    }
}

Example incorrect 1.7.1 behavior:

$ java X
Exception in thread "main" java.lang.ArithmeticException: / by zero
        at
org.apache.tools.bzip2.CBZip2OutputStream.mainSort(CBZip2OutputStream.java:1135)
        at
org.apache.tools.bzip2.CBZip2OutputStream.doReversibleTransformation(CBZip2OutputStream.java:1347)
        at
org.apache.tools.bzip2.CBZip2OutputStream.endBlock(CBZip2OutputStream.java:438)
        at
org.apache.tools.bzip2.CBZip2OutputStream.close(CBZip2OutputStream.java:389)
        at X.main(X.java:5)

Example incorrect behavior of current code:

$ (echo -n "BZ"; java X) | bunzip2

bunzip2: Data integrity error when decompressing.
        Input file = (stdin), output file = (stdout)

It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.

You can use the `bzip2recover' program to attempt to recover
data from undamaged sections of corrupted files.

Behavior with this patch applied, bunzip2 creates zero-length output as
expected:

$ (echo -n "BZ"; java -cp .:/tmp/ant-svn/src/main X) | bunzip2 | wc -c
0

Note that last is set to -1 only in initBlock() which is called only from the
constructor and from writeRun().  However, after initBlock() is called from
writeRun(), writeRun() calls itself again and last is guaranteed not to be -1
afterwards.  Therefore my last == -1 check is true only if the stream is empty,
and in all other cases the behavior is not changed.


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

Mime
View raw message