Skip to content

Reject file lengths that do not fit in usize - #21

Merged
EliteTK merged 1 commit into
mainfrom
tk/fix-usize-truncation
Aug 28, 2026
Merged

Reject file lengths that do not fit in usize#21
EliteTK merged 1 commit into
mainfrom
tk/fix-usize-truncation

Conversation

@EliteTK

@EliteTK EliteTK commented Aug 28, 2026

Copy link
Copy Markdown
Member

Previously on 32 bit platforms we'd end up potentially accepting the size initially, even if it was wrong, and then either returning errors or panicking.

Now we just return the same consistent error that the upstream mmap crate gives when the requested size is too large.

The problem of always relying on mmap is that it's limited to 2GiB for 32 bit platforms anyway. So there should be a better fallback here.

But for now this just makes the errors more consistent, since for any size under 4GiB but above 2GiB on 32 bit we'd give this error, with any truncated size which fell outside this range getting incorrectly accepted with no error.

Previously on 32 bit platforms we'd end up potentially accepting the
size initially, even if it was wrong, and then either returning errors
or panicking.

Now we just return the same consistent error that the upstream mmap
crate gives when the requested size is too large.

The problem of always relying on mmap is that it's limited to 2GiB for
32 bit platforms anyway. So there should be a better fallback here.

But for now this just makes the errors more consistent, since for any
size under 4GiB but above 2GiB on 32 bit we'd give this error, with any
truncated size which fell outside this range getting incorrectly
accepted with no error.
@EliteTK
EliteTK merged commit bfd4b0e into main Aug 28, 2026
3 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