Skip to content

Huge memory allocation due to implicit cast from signed int to size_t #1237

@rohanpadhye

Description

@rohanpadhye

Symptom: Unnecessary huge memory allocation (4GB) for tiny malformed file (21 bytes).
Affects: v3.4.0 and master.

Cause:
When decoding a malformed LZ4 input in legacy format having value 0xFBFFFFFF in compressed data field, libarchive allocates 4GB in a single malloc of __archive_read_filter_ahead().

This smells like a bug, because (1) int compressed in lz4_filter_read_legacy_stream is read as negative value -5, which causes (2) a bounds check to be deemed safe, and then (3) there is an implicit conversion of signed to unsigned integer to argument size_t min of __archive_read_filter_ahead, making the value of min to be 0xFFFFFF, leading to (4) an allocation of about 4GB.

I can attach an input here to repro if required. Please confirm if this is indeed a bug.

Found by: Fuzzing with FuzzFactory

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