Fix setmaxstdio crash on Windows with values exceeding c_int::MAX#75
Merged
Fix setmaxstdio crash on Windows with values exceeding c_int::MAX#75
Conversation
Co-authored-by: Nugine <30099658+Nugine@users.noreply.github.com>
Co-authored-by: Nugine <30099658+Nugine@users.noreply.github.com>
Co-authored-by: Nugine <30099658+Nugine@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Conduct final review before 1.0 release
Fix setmaxstdio crash on Windows with values exceeding c_int::MAX
Dec 7, 2025
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical crash bug in setmaxstdio on Windows where passing values exceeding c_int::MAX caused integer overflow and undefined behavior. The fix adds input validation to reject such values with a proper error before the unsafe cast occurs.
Key Changes:
- Added bounds checking to reject values exceeding
c_int::MAXwithInvalidInputerror - Enhanced documentation to clarify platform limits and error conditions
- Added comprehensive test coverage for overflow scenarios (
u32::MAXandc_int::MAX + 1)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/windows.rs | Added input validation before casting to c_int to prevent overflow; updated documentation to explain limits and error conditions |
| tests/it/windows.rs | Added two new tests to verify that overflow values are properly rejected with InvalidInput error |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Calling
setmaxstdio(u32::MAX)caused crashes due to integer overflow when casting toc_int. Values exceeding 2,147,483,647 wrapped to negative numbers, triggering undefined behavior in Windows CRT's_setmaxstdio.Changes
c_int::MAXwithInvalidInputerror before calling underlying C functionu32::MAXand boundary conditionsExample
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.