Skip to content

decompressing error #3

@gitPhate

Description

@gitPhate

Hi, I was doing some tests, and I encountered an error compressing and decompressing 64 kb of text with the maximum window size of 9220
I did this test:

String msg = new String(Files.readAllBytes(Paths.get("C:\\path\\to\\file", "test_data.txt"))); // input
String x = LZ77.compressStr(msg);
String y = LZ77.decompressStr(x);
System.out.println(x.equalsIgnoreCase(y));

I get

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -10
    at java.lang.String.substring(String.java:1960)
    at lz77.LZ77.decompress(LZ77.java:216)
    at lz77.LZ77.decompressStr(LZ77.java:82)
    at Main.main(Main.java:29)

Which is the same error as the one in the c# impl.
Data is just a random text, here's the link: http://pastebin.com/fywqdyi3

I also tried to compress the same data with the max window length (9220) using this online tool: http://www.geocities.ws/diogok_br/lz77/demo.html. The compression works, but decompressing loses data. Example using the online tool and the same 64kb input data: http://pastebin.com/7VYcT7t6
As you can see in the decompressed text there are some scattered weird chars, and the size is 65125 bytes instead of the original 65536 chars of the input.

As I don't know the algorithm, could you fix this?

PS: that online tool uses your js version, here's their source code: http://www.geocities.ws/diogok_br/lz77/lz77.js
so the problem is for all versions

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