Skip to content

BUG: «Src size is incorrect» on correct file #360

@danila-schelkov

Description

@danila-schelkov

Hello! I caught a problem while using your library.

I uploaded the problematic file named buildings.zip, because GitHub forbid to load file with extension .zstd. It is just a compressed binary file, not an archive. Python built-in module can decompress it, as far as original C library. So, the problem occured only in zstd-jni. I used latest version of the library (v1.5.7-3) from maven repo. Windows and macOS both have the same problem with this file.

Image

Caught Exception:

com.github.luben.zstd.ZstdException: Src size is incorrect
	at com.github.luben.zstd.ZstdDecompressCtx.decompressByteArray(ZstdDecompressCtx.java:224)
	at com.github.luben.zstd.ZstdDecompressCtx.decompress(ZstdDecompressCtx.java:356)
	at com.github.luben.zstd.ZstdDecompressCtx.decompress(ZstdDecompressCtx.java:373)
	at com.github.luben.zstd.Zstd.decompress(Zstd.java:1323)
	at dev.donutquine.swf.file.compression.Zstandard.decompress(Zstandard.java:24)
	at dev.donutquine.swf.file.compression.Zstandard.decompress(Zstandard.java:10)
package dev.donutquine.swf.file.compression;

import com.github.luben.zstd.Zstd;

public final class Zstandard {
    private Zstandard() {
    }

    public static byte[] decompress(byte[] compressedData, int offset) {
        return decompress(compressedData, offset, compressedData.length - offset);
    }

    public static byte[] decompress(byte[] compressedData, int offset, int length) {
        int decompressedSize = (int) Zstd.getFrameContentSize(compressedData, offset, length);

        byte[] zstdContent;
        if (offset > 0 || length != compressedData.length - offset) {
            zstdContent = new byte[length];
            System.arraycopy(compressedData, offset, zstdContent, 0, zstdContent.length);
        } else {
            zstdContent = compressedData;
        }

        return Zstd.decompress(
            zstdContent,
            decompressedSize
        );
    }

    public static byte[] compress(byte[] data) {
        return Zstd.compress(data);
    }
}

buildings.zip

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