Skip to content

Avoid reading ignored chunks or chunks with invalid size #621

@fintelia

Description

@fintelia

Currently, the decoder reads all bytes of a chunk into an in-memory buffer and then calls parse_chunk to decide whether the chunk is valid or should be ignored. This is unfortunate because it means that an ignored chunk or one with a bogus size will still cause us to read a large amount of data into memory. If low decoding limits are in use, this might even trigger a limits exceeded error. Instead, we should decide upfront whether we actually want the full contents of a given chunk. If not, we should skip past the chunk without bothering to save it.

A related question is what to do with chunks that are supported, but whose size field is larger than allowed? For instance, an sBIT chunk should be at most 4-bytes. If we encounter an image with a 10 MB sBIT chunk, should we only read the first 4-bytes or should we consider the whole thing invalid and entirely ignore it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions