Skip to content

Corrupt TIFFs created for incompressible data using zlib compression #68

@twotabbies

Description

@twotabbies

https://github.com/jai-imageio/jai-imageio-core/blob/master/src/main/java/com/github/jaiimageio/impl/plugins/tiff/TIFFDeflater.java#L90 counts the number of 32Ki blocks based on the input size, and then allocates a compression buffer assuming that zlib compression will, in the worst case, add at most 5 bytes per 32k block, plus a 6 byte header. This is incorrect: https://www.zlib.net/zlib_tech.html says "the only expansion is an overhead of five bytes per 16 KB

block (about 0.03%), plus a one-time overhead of six bytes for the entire stream" - note the block size!

If the input data is incompressible, the resulting TIFF file is corrupt as the zlib data is truncated, due to the buffer being too small. An example file is attached (gzipped because github won't accept a plain .tif).
test.tif.gz

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions