commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stefan Bodewig (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (COMPRESS-309) BZip2CompressorInputStream return value wrong when told to read to a full buffer.
Date Fri, 20 Feb 2015 16:19:11 GMT

     [ https://issues.apache.org/jira/browse/COMPRESS-309?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Stefan Bodewig resolved COMPRESS-309.
-------------------------------------
       Resolution: Fixed
    Fix Version/s: 1.10

fixed with svn revision 1661151 - thanks!

> BZip2CompressorInputStream return value wrong when told to read to a full buffer.
> ---------------------------------------------------------------------------------
>
>                 Key: COMPRESS-309
>                 URL: https://issues.apache.org/jira/browse/COMPRESS-309
>             Project: Commons Compress
>          Issue Type: Bug
>          Components: Compressors
>    Affects Versions: 1.4.1, 1.9
>            Reporter: Nathan Kronenfeld
>              Labels: bzip2, compression
>             Fix For: 1.10
>
>
> BZip2CompressorInputStream.read(buffer, offset, length) returns -1 when given an offset
equal to the length of the buffer.
> This indicates, not that the buffer was full, but that the stream was finished.
> It seems like a pretty stupid thing to do - but I'm getting this when trying to use Kryo
serialization (which is probably a bug on their part, too), so it does occur and has negative
affects.
> Here's a JUnit test that shows the problem specifically:
> {noformat}
> 	@Test
> 	public void testApacheCommonsBZipUncompression () throws Exception {
> 		// Create a big random piece of data
> 		byte[] rawData = new byte[1048576];
> 		for (int i=0; i<rawData.length; ++i) {
> 			rawData[i] = (byte) Math.floor(Math.random()*256);
> 		}
> 		// Compress it
> 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
> 		BZip2CompressorOutputStream bzipOut = new BZip2CompressorOutputStream(baos);
> 		bzipOut.write(rawData);
> 		bzipOut.flush();
> 		bzipOut.close();
> 		baos.flush();
> 		baos.close();
> 		// Try to read it back in
> 		ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
> 		BZip2CompressorInputStream bzipIn = new BZip2CompressorInputStream(bais);
> 		byte[] buffer = new byte[1024];
> 		// Works fine
> 		Assert.assertEquals(1024, bzipIn.read(buffer, 0, 1024));
> 		// Fails, returns -1 (indicating the stream is complete rather than that the buffer

> 		// was full)
> 		Assert.assertEquals(0, bzipIn.read(buffer, 1024, 0));
> 		// But if you change the above expected value to -1, the following line still works
> 		Assert.assertEquals(1024, bzipIn.read(buffer, 0, 1024));
> 		bzipIn.close();
> 	}
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message