You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Nathan Kronenfeld (JIRA)" <ji...@apache.org> on 2015/02/18 18:23:11 UTC
[jira] [Created] (COMPRESS-309) BZip2CompressorInputStream return
value wrong when told to read to a full buffer.
Nathan Kronenfeld created COMPRESS-309:
------------------------------------------
Summary: 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.9, 1.4.1
Reporter: Nathan Kronenfeld
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)