Skip to content

Report huge durations as invalid instead of raising decimal.Overflow#1532

Open
cognis-digital wants to merge 1 commit into
python-jsonschema:mainfrom
cognis-digital:fix/duration-decimal-overflow
Open

Report huge durations as invalid instead of raising decimal.Overflow#1532
cognis-digital wants to merge 1 commit into
python-jsonschema:mainfrom
cognis-digital:fix/duration-decimal-overflow

Conversation

@cognis-digital

Copy link
Copy Markdown

Fixes #1511.

The duration format checker delegates to isoduration.parse_duration, which parses each numeric component with Decimal(...). When a component's magnitude exceeds the decimal context's Emax (e.g. P1E1000000D, or a digit run longer than Emax), Decimal raises decimal.Overflow. Because the checker was registered only with raises=isoduration.DurationParsingException, and decimal.Overflow is an ArithmeticError rather than a DurationParsingException, the exception propagated uncaught out of format validation instead of the instance being reported invalid.

Such strings are not valid RFC 3339 Appendix A durations (the grammar is 1*DIGIT, no exponent), so they should be reported invalid. This broadens the checker's caught exceptions to include decimal.Overflow.

Added regression tests for both the large-exponent and long-digit-run cases, guarded with skipUnless so they skip when the optional isoduration dependency isn't installed.

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 python-jsonschema | 🛠️ Build #33753280 | 📁 Comparing 17c6f31 against latest (81f7a76)

  🔍 Preview build  

1 file changed
± _modules/jsonschema/_format/index.html

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.

is_duration raises an uncaught decimal.Overflow on a duration with a large exponent

1 participant