Skip to content

OutOfMemoryError on corrupted png file #534

@Draczech

Description

@Draczech

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 #273 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions