Skip to content

Fix u32 overflow in the Rust duration parser - #1017

Open
Sharadhi-v98 wants to merge 1 commit into
python-pendulum:masterfrom
Sharadhi-v98:rust-duration-checked-add
Open

Sharadhi-v98 wants to merge 1 commit into
python-pendulum:masterfrom
Sharadhi-v98:rust-duration-checked-add

Conversation

@Sharadhi-v98

Copy link
Copy Markdown
  1. parse_duration_number accumulates each unit's digits into a u32 with a plain multiply and add, and the hours, minutes and days accumulators (plus the weeks-fraction carry onto days) are added to unchecked as well.
  2. Release wheels set overflow-checks = false, so the value wraps silently: PT4294967296S parses to an empty Duration, P4294967297D to one day and PT4294967295H1H to zero hours. A debug build panics on the same input and the PanicException escapes the parser's ValueError handling.

Made the digit accumulation and those additions checked, so an oversized value fails with a ParseError like the existing timezone offset bound.

  • Added tests for changed code.
  • Updated documentation for changed code.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant