Skip to content

Fix OverflowError for a large 32-bit usize - #746

Merged
davidhewitt merged 3 commits into
pydantic:mainfrom
rewitt94:fix-32bit-size-overflow-panics
Aug 17, 2026
Merged

Fix OverflowError for a large 32-bit usize#746
davidhewitt merged 3 commits into
pydantic:mainfrom
rewitt94:fix-32bit-size-overflow-panics

Conversation

@rewitt94

@rewitt94 rewitt94 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Two issues would cause crashes (traps) in wasm (needs a 32-bit build):

  • collections.deque([], 2**40)
  • bytes(2**40)

Raise an OverflowError error pre-emptively instead.


Summary by cubic

Fixes 32-bit wasm traps by raising OverflowError when size-like ints exceed usize. Previously deque([], 2**40) and bytes(2**40) crashed; now they raise CPython-matching messages. 64-bit behavior is unchanged.

  • Add crates/monty-js/__test__/wasm_word_size.spec.ts to assert exceptions and session survival in @pydantic/monty/wasm (skipped in browser).
  • bytes: make usize::try_from fallible and map errors to OverflowError via overflow_index_sized_int.
  • deque: make maxlen conversion fallible and map errors to OverflowError via overflow_c_ssize_t to match CPython wording.
  • Rename internal helper overflow_repeat_count to overflow_index_sized_int; update callers in long_int.rs.
  • Docs: clarify 32-bit vs 64-bit behavior and note bytes edge cases; pool architecture limitations wording updated.

Written for commit a1d3eda. Summary will update on new commits.

Review in cubic

Two issues would cause crashes (traps) in wasm (needs a 32-bit build):
- `collections.deque([], 2**40)`
- `bytes(2**40)`

Raise an OverflowError error pre-emptively instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/monty/src/types/bytes.rs 0.00% 0 Missing and 1 partial ⚠️
crates/monty/src/types/deque.rs 0.00% 0 Missing and 1 partial ⚠️
crates/monty/src/types/long_int.rs 66.66% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 7 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread crates/monty-js/__test__/wasm_word_size.spec.ts Outdated
Comment thread limitations/pool-architecture.md Outdated
@codspeed-hq

codspeed-hq Bot commented Aug 14, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 36 untouched benchmarks
⏩ 16 skipped benchmarks1


Comparing rewitt94:fix-32bit-size-overflow-panics (a1d3eda) with main (edeb82a)

Open in CodSpeed

Footnotes

  1. 16 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Comment thread limitations/pool-architecture.md Outdated
@davidhewitt
davidhewitt enabled auto-merge (squash) August 17, 2026 10:32
@davidhewitt
davidhewitt merged commit 98748e2 into pydantic:main Aug 17, 2026
42 checks passed
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.

2 participants