Skip to content

Unbounded memory allocation in header parsing #572

Open

Description

@sneurlax

The helper Header::read and its buffered/async variants (fn read, fn read_async, fn read_buffered, and fn read_async_buffered) call the nom parser in a loop. When the parser returns Incomplete(Needed::Size(n)), the code blindly executes data.resize(m + n, 0) and then read_exact the additional bytes. Because n is attacker-influenced and no upper bound is enforced, a hostile file can force arbitrarily large allocations, leading to memory-exhaustion denial of service.

Recommendation:

Abort header parsing when the accumulated buffer exceeds 64 KiB (the limit used by the reference Go implementation) or a tighter value mandated by project policy. Propagate a DecryptError::InvalidHeaderSize to callers.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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