Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

turbojpeg: Fix JPEG decoding from TIFFs with versions >=2.1.4 #286

Merged
merged 1 commit into from
May 7, 2024

Conversation

jbaiter
Copy link
Member

@jbaiter jbaiter commented May 6, 2024

turbojpeg introduced support for abbreviated datastreams in 2.1.4, returning early from tjDecompressHeader3 if such a datastream is detected, and thus not updating the values for width, height colorspace and subsampling that we relied on.

This didn't cause issues with the standard ImageIO TIFFImageReader from the com.sun package, since it always completely decoded the JPEG. However, the TwelveMonkeys implementation was more efficient and only used the abbreviated datastream from the TIFF Header, as intended.

This broke our code, since we assumed that width, height, colorspace and subsampling were always available.

Luckily the fix was rather trivial: Simply check if the values were set tor not and return null if they weren't. The null info value doesn't cause any issues, since by the time the values are needed, we already have a new input with the full datastream available and will read the info from there.

turbojpeg introduced support for `abbreviated datastreams` in 2.1.4,
returning early from `tjDecompressHeader3` if such a datastream is
detected, and thus not updating the values for width, height colorspace
and subsampling that we relied on.

This didn't cause issues with the standard ImageIO `TIFFImageReader`
from the `com.sun` package, since it always completely decoded the JPEG.
However, the TwelveMonkeys implementation was more efficient and only
used the abbreviated datastream from the TIFF Header, as intended.

This broke our code, since we assumed that width, height, colorspace and
subsampling were always available.

Luckily the fix was rather trivial: Simply check if the values were set
tor not and return `null` if they weren't. The `null` info value doesn't
cause any issues, since by the time the values are needed, we already
have a new input with the full datastream available and will read the
info from there.
@jbaiter jbaiter requested a review from stefan-it May 6, 2024 17:32
stefan-it
stefan-it previously approved these changes May 7, 2024
@stefan-it stefan-it merged commit b63e7b4 into main May 7, 2024
6 checks passed
@morpheus-87 morpheus-87 deleted the fix-twelvemonkeys-tiffjpeg branch May 15, 2024 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants