Skip to content

[ouch 0.6.1] \rename_or_increment_filename overflow in rename-conflict handling #943

@xc01

Description

@xc01

Version

0.6.1

Description

In ouch 0.6.1, the older rename-conflict logic could overflow when incrementing a numeric suffix, e.g.:

let number = number_str.parse::<u32>().unwrap_or(0);
format!("{}_{}", base, number + 1)

If the suffix was 4294967295 (u32::MAX), number + 1 could overflow and panic (reproducible in debug builds).

I see that newer code now uses find_available_filename_by_renaming with for i in 1.., so the old parse-and-increment path seems gone.
As a small hardening suggestion, it might still be nice to add an explicit boundary guard (or graceful fallback) for the index growth path as well, even though reaching that boundary is extremely unlikely in practice.

Thank you.

Current Behavior

No response

Expected Behavior

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions