Bug 32200 - CBZip2InputStream and CBZip2OutputStream produce strange exceptions when there's no data
Summary: CBZip2InputStream and CBZip2OutputStream produce strange exceptions when ther...
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.6.2
Hardware: All other
: P3 normal (vote)
Target Milestone: 1.8.0
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-12 15:25 UTC by sls
Modified: 2008-07-17 00:01 UTC (History)
1 user (show)



Attachments
Fixes and Unit test for CBZip2* (5.45 KB, patch)
2005-02-28 12:56 UTC, Kev Jackson
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description sls 2004-11-12 15:25:45 UTC
If you create a CBZip2OutputStream and immediately close it you get an 
ArithmeticException.

If you create a CBZip2InputStream with no input you get a 
NullPointerException.  GZIPInputStream throws a EOFException which makes more 
sense.

Example:

import org.apache.tools.bzip2.*;
import java.io.*;

public class AntBug {
    public static void main(String[] args) {
	try {
	    CBZip2InputStream cb =
		new CBZip2InputStream(new ByteArrayInputStream(new byte[0]));
	    cb.close();
	} catch (Exception e) {
	    e.printStackTrace();
	}
	try {
	    CBZip2OutputStream cb =
		new CBZip2OutputStream(new ByteArrayOutputStream());
	    cb.close();
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }
}

Produces:

java.lang.NullPointerException
        at org.apache.tools.bzip2.CBZip2InputStream.bsR
(CBZip2InputStream.java:285)
        at org.apache.tools.bzip2.CBZip2InputStream.bsGetUChar
(CBZip2InputStream.java:303)
        at org.apache.tools.bzip2.CBZip2InputStream.initBlock
(CBZip2InputStream.java:192)
        at org.apache.tools.bzip2.CBZip2InputStream.<init>
(CBZip2InputStream.java:140)
        at AntBug.main(AntBug.java:7)
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 AntBug.main(AntBug.java:16)
Comment 1 Kev Jackson 2005-02-28 12:56:31 UTC
Created attachment 14374 [details]
Fixes and Unit test for CBZip2*

The unit test shows the behaviour, and the minor changes I've made allow the
tests to pass, but I'm not confident about these changes not breaking anything
(throwing an Exception that we didn't used to throw will probably be a BC
issue)

- removed trailing ; when found
Comment 2 Stefan Bodewig 2008-07-17 00:01:57 UTC
svn revision 677514