TwelveMonkeys icon indicating copy to clipboard operation
TwelveMonkeys copied to clipboard

TIFF read and write binary content non -deterministic

Open BuZZ-dEE opened this issue 10 months ago • 2 comments

Describe the bug

Generated binary content for TIFF file differs from v.3.4.2 to v3.12.0 which could I understand. The problem we now see, the binary content also differs randomly for v3.12.0, because we have a test that reads a TIFF file and then writes the TIFF file on the filesystem. Then we check the generated binary content to the expected binary content (new generated with v3.12.0), which sometimes differs and sometimes not.

Version information

  1. The version of the TwelveMonkeys ImageIO library in use. 3.12.0

  2. The exact output of java --version (or java -version for older Java releases). For example:

    openjdk version "24" 2025-03-18 OpenJDK Runtime Environment Temurin-24+36 (build 24+36) OpenJDK 64-Bit Server VM Temurin-24+36 (build 24+36, mixed mode, sharing)

  3. Extra information about OS version, server version, standalone program or web application packaging, executable wrapper, etc. Please state exact version numbers where applicable.

To Reproduce

Expected behavior The binary content for the TIFF file should always the same as the expected TIFF file.

Example code

Less is more. Don't add your entire project, only the code required to reproduce the problem. 😀

Sample file(s) 3_imagebilder_g.zip

Additional context Add any other context about the problem here.

BuZZ-dEE avatar Jun 13 '25 12:06 BuZZ-dEE

we have a test that reads a TIFF file and then writes the TIFF file on the filesystem. Then we check the generated binary content to the expected binary content (new generated with v3.12.0), which sometimes differs and sometimes not

Can you please share this test, that would make it a lot easier for me to reproduce and understand. 😀

PS: While most TIFF compressions are lossless and should create the same output every time, this is not the case with all compressions (ie. JPEG). The test image seems to use LZW compression though, so I assume that is not the problem here.

haraldk avatar Jun 13 '25 14:06 haraldk

I am unable to reproduce this issue.

I wrote the following program, and it always runs until completion, with no difference in output. I used your attached TIFF as input, in case that should matter. I even tried increasing the number of iteration to 10 000. Still no diff.

public class TIFFDiff {
    public static void main(String[] args) throws IOException {
        File input = new File(args[0]);
        BufferedImage image = ImageIO.read(input);

        byte[] previous = null;
        ByteArrayOutputStream output = new ByteArrayOutputStream();

        for (int i = 0; i < 1000; i++) {
            ImageIO.write(image, "TIFF", output);

            byte[] current = output.toByteArray();

            if (i > 0) {
                if (!Arrays.equals(previous, current)) {
                    throw new AssertionError("Arrays differ after " + i + " iterations");
                }
            }

            if (i % 10 == 0) {
                System.out.print(".");
            }

            output.reset();
            previous = current;
        }

        System.out.println();
    }
}

I also made variations where I write to a temp file, and/or write using LZW compression. Still no difference in output.

haraldk avatar Jun 17 '25 09:06 haraldk

Closing as not reproducible. Feel free to reopen if you can provide a test. 😀

haraldk avatar Jun 20 '25 11:06 haraldk