question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OutOfMemoryError while reading tif

See original GitHub issue

Hi, we were getting following OOME while reading one of our tif images:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at com.twelvemonkeys.imageio.metadata.tiff.TIFFReader.readValue(TIFFReader.java:461)
	at com.twelvemonkeys.imageio.metadata.tiff.TIFFReader.readValueAt(TIFFReader.java:372)
	at com.twelvemonkeys.imageio.metadata.tiff.TIFFReader.readEntry(TIFFReader.java:345)
	at com.twelvemonkeys.imageio.metadata.tiff.TIFFReader.readIFD(TIFFReader.java:178)
	at com.twelvemonkeys.imageio.metadata.tiff.TIFFReader.readSubIFDs(TIFFReader.java:229)
	at com.twelvemonkeys.imageio.metadata.tiff.TIFFReader.readIFD(TIFFReader.java:194)
	at com.twelvemonkeys.imageio.metadata.tiff.TIFFReader.readLinkedIFDs(TIFFReader.java:151)
	at com.twelvemonkeys.imageio.metadata.tiff.TIFFReader.read(TIFFReader.java:132)
	at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader.readMetadata(TIFFImageReader.java:187)
	at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader.readIFD(TIFFImageReader.java:380)
	at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:916)
	at javax.imageio.ImageIO.read(ImageIO.java:1462)

I suppose that the image metadata are corrupted as I was able to get rid of this error by altering the image (e.q. by opening the image and saving again in graphical editor or manually just with the text editor). Would be nice if you could improve the twelvemonkeys implementation and skip loading of metadata to prevent OOME in such case as other tools can read the image without crash.

Code to read image: BufferedImage image = ImageIO.read(new URL(wrong)); Tested with imageio 3.7.0 and 3.8.1.

The problematic image is attached in .zip as tif format is not supported as attachment. P07.61-3863-76_M178-Farbe.zip

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
haraldkcommented, Jan 3, 2022

FIY: I added a small fix that will detect this situation and handle it gracefully, even if reading from URL. Will be included in next release.

1reaction
jan-pestacommented, Dec 30, 2021

Hi Harald, thanks a lot. You’re right. The image can be read as a file. The exception above was my fault - I used original URL source with “file:///” protocol prefix at the beginning of the path. Now it works fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Out of memory exception when loading tif file in a picture box
i solve this problem by changing Pixel format of my loaded image using this code : Bitmap orig = new Bitmap(filePath); Bitmap clone...
Read more >
Plotting tiff file giving Memory Error - GIS Stack Exchange
A MemoryError like this usually means that something ran out of memory (i.e. it's too big for your system to process as is)....
Read more >
Concatenating tif files into one causing out of memory issues
We are getting out of memory error while concatenation get tif files using aspose.imaging.jar ... Details: There is no more data to read....
Read more >
OutOfMemory exceptions importing ome.tiff files over 9 or 10GB
I have several ome.tiff files that I have exported from our software ... Files around 9GB are throwing Java heap space out of...
Read more >
High resolution TIFF images causing Out Of Memory during ...
In the case of the 16K image, the conversion processes consume all available heap memory and turning to Out Of Memory error. In...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found