You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Display more specific error message when failing to decompress an empty stream #89
In Apache Spark, I've run into problems where our own code mistakenly tries to decompress an empty stream using SnappyInputStream. In this case, snappy-java produces an error like
In SnappyInputStream.readHeader, there's a check that tests whether the header is shorter than expected or doesn't match the SnappyOutputStream magic header:
// Quick test of the header if (readBytes < header.length || header[0] != SnappyCodec.MAGIC_HEADER[0]) {
// do the default uncompressionreadFully(header, readBytes);
return;
}
In the case where readBytes is 0, it would be helpful if snappy-java reported an error such as new IOException("Cannot decompress empty stream") instead of falling back on the regular Snappy decompression and throwing a confusing PARSING_ERROR.
I want to confirm whether throwing an IOException for an empty input is the expected behaviour? It is also possible to finish decompression without throwing exception if the input is empty.
@JoshRosen
I fixed the problem by not throwing IOException since it should be the default behaviour. You can check the emptiness by looking at the size of the written data (i.e. return values of int read(dst, offset, len))
According to the Snappy spec, is an empty stream / array a valid input to the decompressor? If I compress an empty byte array / stream, then shouldn't that produce non empty compressed output that consists only of the magic header? As far as I can tell, Snappy will never write an empty output and therefore attempting to decompress an empty stream is always an error.
I want to confirm whether throwing an IOException for an empty input is the expected behaviour? It is also possible to finish decompression without throwing exception if the input is empty.
—
Reply to this email directly or view it on GitHub.
To capture the empty input stream error, I added SnappyIOException (extended from IOException), to make it easy to detect the error type by using the pattern matching in Scala.
This looks good to me; it will be a huge debugging aid for us, since it's kind of difficult / expensive to add these checks at higher levels of the stack. Thanks for your help!
Just want to thank you @xerial for the incredibly quick response on this issue! It's a big help for the Spark community that you're so on top of these sorts of things. I really appreciate it and I think many others do too.
You can see our struggles with identifying the cause of the Spark bug at SPARK-3630
@ash211
Thanks for letting me know how spark community handling this problem. It looks like they are doing very nice jobs for identifying the cause of the errors.
@JoshRosen
Are you using snappy-java-1.1.1.6, which fixes #92?
Please let me know if there is something I can do for resolving the issue. Releasing a new version of snappy-java can be done in my spare time.
We haven't upgraded to 1.1.1.6 yet (I've been super-busy and this slipped through the cracks), but I've opened apache/spark#3287 to upgrade to that version in Spark. Thanks again for the fix!
Activity
xerial commentedon Oct 23, 2014
Thanks for reporting problem. I haven't checked the case when the input is empty. I'll fix this problem.
xerial commentedon Oct 23, 2014
I want to confirm whether throwing an IOException for an empty input is the expected behaviour? It is also possible to finish decompression without throwing exception if the input is empty.
#89: Fixes SnappyInputStream not to throw an IOException when the inp…
xerial commentedon Oct 23, 2014
@JoshRosen
I fixed the problem by not throwing IOException since it should be the default behaviour. You can check the emptiness by looking at the size of the written data (i.e. return values of
int read(dst, offset, len))Deployed this version as 1.1.1.4-SNAPSHOT:
https://oss.sonatype.org/content/repositories/snapshots/org/xerial/snappy/snappy-java/1.1.1.4-SNAPSHOT/
JoshRosen commentedon Oct 23, 2014
According to the Snappy spec, is an empty stream / array a valid input to the decompressor? If I compress an empty byte array / stream, then shouldn't that produce non empty compressed output that consists only of the magic header? As far as I can tell, Snappy will never write an empty output and therefore attempting to decompress an empty stream is always an error.
xerial commentedon Oct 23, 2014
Good point. Actually
Snappy.compress(new byte[0])produces 1-byte result. So SnappyInputStream must throw an exception. I'll modify the code. Thanks.#89: Add SnappyIOException to distinguish empty input, incompatible f…
xerial commentedon Oct 23, 2014
To capture the empty input stream error, I added SnappyIOException (extended from IOException), to make it easy to detect the error type by using the pattern matching in Scala.
Could you review the changes? Thanks in advance.
JoshRosen commentedon Oct 23, 2014
This looks good to me; it will be a huge debugging aid for us, since it's kind of difficult / expensive to add these checks at higher levels of the stack. Thanks for your help!
xerial commentedon Oct 23, 2014
Just released snappy-java-1.1.1.4. It will be available from Maven central in a few hours.
Thanks for the detailed report. It helps me a lot to understand the problem quickly.
[SPARK-4056] Upgrade snappy-java to 1.1.1.5
[SPARK-4056] Upgrade snappy-java to 1.1.1.5
ash211 commentedon Nov 14, 2014
Just want to thank you @xerial for the incredibly quick response on this issue! It's a big help for the Spark community that you're so on top of these sorts of things. I really appreciate it and I think many others do too.
You can see our struggles with identifying the cause of the Spark bug at SPARK-3630
xerial commentedon Nov 15, 2014
@ash211
Thanks for letting me know how spark community handling this problem. It looks like they are doing very nice jobs for identifying the cause of the errors.
@JoshRosen
Are you using snappy-java-1.1.1.6, which fixes #92?
Please let me know if there is something I can do for resolving the issue. Releasing a new version of snappy-java can be done in my spare time.
JoshRosen commentedon Nov 15, 2014
Hi @xerial,
We haven't upgraded to 1.1.1.6 yet (I've been super-busy and this slipped through the cracks), but I've opened apache/spark#3287 to upgrade to that version in Spark. Thanks again for the fix!
[SPARK-4419] Upgrade snappy-java to 1.1.1.6
[SPARK-4419] Upgrade snappy-java to 1.1.1.6
xerial#89: Fixes SnappyInputStream not to throw an IOException when t…
xerial#89: Add SnappyIOException to distinguish empty input, incompat…
xerial#89: Fixes SnappyInputStream not to throw an IOException when t…
xerial#89: Add SnappyIOException to distinguish empty input, incompat…