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

Integer overflow for TIFF stream when splitting large TIFF #676

Open
beig opened this issue May 4, 2022 · 3 comments
Open

Integer overflow for TIFF stream when splitting large TIFF #676

beig opened this issue May 4, 2022 · 3 comments

Comments

@beig
Copy link

beig commented May 4, 2022

Describe the bug
I am trying to extract the first page from a large TIFF (15GB) using TIFFUtilities::split function

Version information

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

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

java version "15.0.2" 2021-01-19
Java(TM) SE Runtime Environment (build 15.0.2+7-27)                       
Java HotSpot(TM) 64-Bit Server VM (build 15.0.2+7-27, mixed mode, sharing)
  1. Extra information about OS version, server version, standalone program or web application packaging, executable wrapper, etc.
    Windows 10 64bit

To Reproduce
Steps to reproduce the behavior:

TIFFUtilities.split(new File("Large_test.tif"), new File("E:\\tmp\\"));

Expected behavior
the individual pages

Stack trace

Exception in thread "main" javax.imageio.IIOException: Integer overflow for TIFF stream
	at com.twelvemonkeys.imageio.metadata.tiff.TIFFWriter.assertIntegerOffset(TIFFWriter.java:514)
	at com.twelvemonkeys.imageio.metadata.tiff.TIFFWriter.writeOffset(TIFFWriter.java:504)
	at com.twelvemonkeys.imageio.metadata.tiff.TIFFWriter.writeIFD(TIFFWriter.java:145)
	at com.twelvemonkeys.imageio.metadata.tiff.TIFFWriter.writeIFD(TIFFWriter.java:127)
@Schmidor
Copy link
Contributor

Schmidor commented May 4, 2022

TIFFUtilities is currently working with 4 byte pointers only and not ready for BigTIFF files.

There are some places, where we must switch from int/long and the com.twelvemonkeys.imageio.metadata.tiff.TIFFWriter initialisation depending on the input.

@haraldk
Copy link
Owner

haraldk commented May 4, 2022

Should be doable...

We could somehow expose the TIFF/BigTIFF flavor or pointer size in the IFD or TIFFDirectory, or just make it a parameter to TIFFPage based on the input (but then TIFFUtilities would need to figure out the input type somehow).

The TIFFWriter does handle BigTIFF already, but you need to tell it you want BigTIFF (or 64 bit pointers). But there might be some places where the TIFFUtilities methods write offsets directly, and that needs to be fixed as well. There's a method TIFFWriter.writeOffset(ImageOutputStream, long) that was made for this.

Happily accepting a PR! 😀

@haraldk
Copy link
Owner

haraldk commented May 4, 2022

Hmmm... I started work on this, but I think I found some offset issues in the TIFFImageWriter as well, related to how we write strip/tile offsets etc. 😕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants