Skip to content

Display more specific error message when failing to decompress an empty stream #89

Description

@JoshRosen

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

java.io.IOException: PARSING_ERROR(2)
atorg.xerial.snappy.SnappyNative.throw_error(SnappyNative.java:84)
atorg.xerial.snappy.SnappyNative.uncompressedLength(NativeMethod)
atorg.xerial.snappy.Snappy.uncompressedLength(Snappy.java:594)
atorg.xerial.snappy.SnappyInputStream.readFully(SnappyInputStream.java:125)
atorg.xerial.snappy.SnappyInputStream.readHeader(SnappyInputStream.java:88)
atorg.xerial.snappy.SnappyInputStream.<init>(SnappyInputStream.java:58)

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions