Skip to content

printf Format String Parsing Overflow Causes Panic #9697

@sylvestre

Description

@sylvestre

Component

printf

Description

When parsing width/precision values in format strings, printf does not properly handle integer overflow. When extremely large values are passed, the eat_number function causes the process to panic and crash due to unwrap().

Under GNU:

printf '%999999999999999999999999d' 1
1

Under uutils:

printf '%999999999999999999999999d' 1

thread 'main' panicked at src/uucore/src/lib/features/format/spec.rs:599:18:
called `Result::unwrap()` on an `Err` value: ParseIntError { kind: PosOverflow }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Test / Reproduction Steps

# Provide commands and setup to reproduce

Impact

The process panicked and crashed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions