TIFF: fix channel unpacking when supplied buffer is too large - #4478
Merged
Conversation
Member
Author
sbesson
approved these changes
Aug 24, 2026
sbesson
left a comment
Member
There was a problem hiding this comment.
Tested using the sample files linked from the original issue and a modified version of the script linked in the description to take the TIFF file as a second argument and report the incorrect byte values check as well as exceptions while calling openBytes.
With Bio-Formats 8.5.0, calling the sample files with increasing number of runs starting failing from N=4 for the 16-bit files and N=1 for the 8-bit files
sbesson@Sebastien-GS-MacBook-Pro-2025 Downloads % for i in $(seq 0 10); do java -cp bftools/bioformats_package.jar:. BytesTest $i DeltaE_16bit_gamma1.0.tif; done
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 1
total incorrect: 0, total bad: 2
total incorrect: 1, total bad: 2
total incorrect: 2, total bad: 2
total incorrect: 3, total bad: 2
total incorrect: 4, total bad: 2
total incorrect: 4, total bad: 3
sbesson@Sebastien-GS-MacBook-Pro-2025 Downloads % for i in $(seq 0 10); do java -cp bftools/bioformats_package.jar:. BytesTest $i DeltaE_16bit_gamma2.2.tif; done
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 1
total incorrect: 0, total bad: 2
total incorrect: 1, total bad: 2
total incorrect: 2, total bad: 2
total incorrect: 3, total bad: 2
total incorrect: 4, total bad: 2
total incorrect: 4, total bad: 3
sbesson@Sebastien-GS-MacBook-Pro-2025 Downloads % for i in $(seq 0 10); do java -cp bftools/bioformats_package.jar:. BytesTest $i DeltaE_8bit_gamma1.0.tif; done
total incorrect: 0, total bad: 0
total incorrect: 1, total bad: 0
total incorrect: 2, total bad: 0
total incorrect: 3, total bad: 0
total incorrect: 4, total bad: 0
total incorrect: 5, total bad: 0
total incorrect: 6, total bad: 0
total incorrect: 7, total bad: 0
total incorrect: 8, total bad: 0
total incorrect: 9, total bad: 0
total incorrect: 10, total bad: 0
sbesson@Sebastien-GS-MacBook-Pro-2025 Downloads % for i in $(seq 0 10); do java -cp bftools/bioformats_package.jar:. BytesTest $i DeltaE_8bit_gamma2.2.tif; done
total incorrect: 0, total bad: 0
total incorrect: 1, total bad: 0
total incorrect: 2, total bad: 0
total incorrect: 3, total bad: 0
total incorrect: 4, total bad: 0
total incorrect: 5, total bad: 0
total incorrect: 6, total bad: 0
total incorrect: 7, total bad: 0
total incorrect: 8, total bad: 0
total incorrect: 9, total bad: 0
total incorrect: 10, total bad: 0
With this PR included,
sbesson@Sebastien-GS-MacBook-Pro-2025 Downloads % for i in $(seq 0 10); do java -cp ~/Documents/GitHub/bioformats/artifacts/bioformats_package.jar:. BytesTest $i DeltaE_16bit_gamma1.0.tif; done
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
sbesson@Sebastien-GS-MacBook-Pro-2025 Downloads % for i in $(seq 0 10); do java -cp ~/Documents/GitHub/bioformats/artifacts/bioformats_package.jar:. BytesTest $i DeltaE_16bit_gamma2.2.tif; done
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
sbesson@Sebastien-GS-MacBook-Pro-2025 Downloads % for i in $(seq 0 10); do java -cp ~/Documents/GitHub/bioformats/artifacts/bioformats_package.jar:. BytesTest $i DeltaE_16bit_gamma1.0.tif; done
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
sbesson@Sebastien-GS-MacBook-Pro-2025 Downloads % for i in $(seq 0 10); do java -cp ~/Documents/GitHub/bioformats/artifacts/bioformats_package.jar:. BytesTest $i DeltaE_16bit_gamma2.2.tif; done
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
total incorrect: 0, total bad: 0
Also that the new added unit tests fail with an ArrayIndexOutOfBoundsException with 1e730ef reverted but pass with it included.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4058.
Tested using the file linked from #4058 and slightly modified test code:
That checks for exceptions with large buffers (as in the original test), but also compares the returned bytes against a known-good array without a pre-allocated buffer.
I expect this needs a unit test that uses a TIFF generated from fake data, but am opening first to see if any tests fail overnight.