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 on corrupted png file

See original GitHub issue

Hi, I’m getting OOM error while loading a png file. It is a corrupted file, but this kind of error should be prevented from firing anyway.

File

File location: https://better-essay-service.com/favicon-96x96.png Info: Supposedly 96x96px png file, actual size 8556 bytes, content can be checked via GIMP. Thumbnail: favicon_better_essay_service_com

Stacktrace

    java.lang.OutOfMemoryError: Java heap space
        at com.drew.lang.StreamReader.getBytes(StreamReader.java:71)
        at com.drew.imaging.png.PngChunkReader.extract(PngChunkReader.java:96)
        at com.drew.imaging.png.PngMetadataReader.readMetadata(PngMetadataReader.java:102)

Debug info

Debugging the issue I found out that extracting chunk data works until reader position 8070 in the file. Then calling SequentialReader.getInt32() method results in following:

// Motorola - MSB first (big endian)
return (101 << 24 & 0xFF000000) |
(58 << 16 & 0xFF0000) |
(99 << 8  & 0xFF00) |
(114       & 0xFF);

Valid int value 1698325362 is returned. Then in StreamReader.getBytes(int count) allocation of new byte[1698325362] fails hard.

I guess some sanity check on those values returned should be in place? E.g. when reader tries to allocate more bytes than the actual length of the file is?

Possibly related to https://github.com/drewnoakes/metadata-extractor/issues/273 ?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
drewnoakescommented, May 4, 2021

#535 has been merged (thanks again).

1reaction
drewnoakescommented, Apr 30, 2021

E.g. when reader tries to allocate more bytes than the actual length of the file is?

This is a good strategy. It’s not always straightforward to know how large the file is, however. For example, we may be streaming data with unknown length over a network.

Read more comments on GitHub >

github_iconTop Results From Across the Web

image/png: `fatal error: runtime: out of memory` via `(*decoder ...
It's not a friendly response to corrupt data. This is related to the discussion at #20169, which remains unresolved. I've been trying to...
Read more >
Out Of Memory exception on System.Drawing.Image.FromFile()
It turns out that the "Out Of Memory" occured exactly at the same point each ... This happens when the image file is...
Read more >
IV75409: COM.SUN.IMAGEIO.PLUGINS.PNG ... - IBM
When metadata of malformed/corrupt PNG image has invalid chunk length (image size), it can be very huge and result in OutOfMemoryError while allocating...
Read more >
When the 8000+ images converted using this code out of ...
When the 8000+ images converted using this code out of memory error ... PNG" || System. ... Add("Corrupt FileName:" + fileName); continue; ...
Read more >
Unable to View Issue in JIRA after Attaching a PNG File
Unable to view the issue after attaching PNG file(s) to an issue in ... OutOfMemoryError: Java heap space at com.sun.imageio.plugins.png.
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