Skip to content

Fix setmaxstdio crash on Windows with values exceeding c_int::MAX#75

Merged
Nugine merged 5 commits intomainfrom
copilot/final-review-before-1-0
Dec 7, 2025
Merged

Fix setmaxstdio crash on Windows with values exceeding c_int::MAX#75
Nugine merged 5 commits intomainfrom
copilot/final-review-before-1-0

Conversation

Copy link
Contributor

Copilot AI commented Dec 7, 2025

Calling setmaxstdio(u32::MAX) caused crashes due to integer overflow when casting to c_int. Values exceeding 2,147,483,647 wrapped to negative numbers, triggering undefined behavior in Windows CRT's _setmaxstdio.

Changes

  • Input validation: Reject values > c_int::MAX with InvalidInput error before calling underlying C function
  • Documentation: Clarified platform-dependent limits (typically 8,192 max) and error conditions
  • Tests: Added coverage for u32::MAX and boundary conditions

Example

// Previously: crashed or undefined behavior
setmaxstdio(u32::MAX)?; 

// Now: returns Err with InvalidInput
assert!(setmaxstdio(u32::MAX).is_err());
assert!(setmaxstdio(c_int::MAX as u32 + 1).is_err());

// Valid calls unchanged
setmaxstdio(2048)?; // OK

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

This section details on the original issue you should resolve

<issue_title>Final review before 1.0</issue_title>
<issue_description>The current APIs are nearly stable.

Remaining questions:

  • rlimit will not add cgroups API. cgroups-rs is recommanded now.
  • Is it ok to use u64 as the rlim type for all platforms? (Yes)
  • The signature of rlimit::prlimit seems sightly strange. Is there a better way?
  • setmaxstdio(u32::MAX) can lead to crash. Should it be a feature or a bug?

Related issues:

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits December 7, 2025 10:47
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
Copilot AI requested a review from Nugine December 7, 2025 10:54
@Nugine Nugine marked this pull request as ready for review December 7, 2025 17:06
@Nugine Nugine requested a review from Copilot December 7, 2025 17:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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::MAX with InvalidInput error
  • Enhanced documentation to clarify platform limits and error conditions
  • Added comprehensive test coverage for overflow scenarios (u32::MAX and c_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>
@Nugine Nugine merged commit a065402 into main Dec 7, 2025
35 checks passed
@Nugine Nugine deleted the copilot/final-review-before-1-0 branch December 7, 2025 17:27
@Nugine Nugine mentioned this pull request Dec 7, 2025
5 tasks
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.

Final review before 1.0

3 participants