lz4 / lz4-java

LZ4 compression for Java
Apache License 2.0
1.11k stars 252 forks source link

net.jpountz.lz4.LZ4Exception: Malformed input #78

Closed florianerhard closed 8 years ago

florianerhard commented 8 years ago

When processing the attached file with the following code, I get an LZ4Exception from decomp.decompress(c, 0,b, 0, l). Am I doing something wrong or is it a bug? Btw. this works fine for thousands of other byte arrays...

It does not matter which compressor/decompressor I use. I tested it with the latest version from github (b69d567) as well as the latest release from Maven (1.3.0).

The exception from the safe decompressor is:

Exception in thread "main" net.jpountz.lz4.LZ4Exception: Malformed input at 4338
    at net.jpountz.lz4.LZ4JavaSafeFastDecompressor.decompress(LZ4JavaSafeFastDecompressor.java:57)
    at DecodingError.main(DecodingError.java:25)
        byte[] b = new byte[36412];
        byte[] c = new byte[12109];
        LZ4Compressor comp = LZ4Factory.safeInstance().fastCompressor();
        LZ4FastDecompressor decomp = LZ4Factory.safeInstance().fastDecompressor();

        FileInputStream is = new FileInputStream("test.txt");
        is.read(b, 0, b.length);
        is.close();

        int l = comp.compress(b, 0, b.length, c, 0);
        decomp.decompress(c, 0,b, 0, l);

test.txt

florianerhard commented 8 years ago

Problem solved, it was my fault... it has to be decomp.decompress(c, 0,b, 0, b.length); in the last line... stupid me!

ketan5452 commented 7 years ago

I have one query. If I have only one compressed byte array and I want to decompress it and formed decompressed byte array but I don't know the size of decompress byte array. How should I provide such a implementation?