◐ Shell
clean mode source ↗

Fix test_subprocess and locale by youknowone · Pull Request #6416 · RustPython/RustPython

Walkthrough

Adds runtime input validation: CreateProcess now rejects embedded NUL bytes in optional name and command_line fields; setlocale on Windows gains encoding-length validation for locale strings (including LC_ALL semicolon-separated entries) before calling libc::setlocale.

Changes

Cohort / File(s) Summary
CreateProcess null-byte validation
crates/vm/src/stdlib/winapi.rs
Added runtime checks to reject embedded NUL (\0) characters in the optional name and command_line parameters; returns cstring_error(vm) on failure and aborts process creation before constructing C strings.
Windows locale validation for setlocale
crates/stdlib/src/locale.rs
Added MAX_CP_LEN constant and Windows-only helpers check_locale_name and check_locale_name_all; validate encoding length (post-dot, optional @ modifier) and iterate semicolon-separated locales for LC_ALL before calling libc::setlocale, returning an unsupported-locale error on invalid input.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Review null-byte checks in winapi.rs for both Some/None branches and ensure correct early return semantics and error construction.
  • Validate parsing logic in locale.rs (dot, @ modifier, semicolon splitting) and boundary cases near MAX_CP_LEN.
  • Confirm platform-conditional compilation and that non-Windows paths remain unchanged.
  • Test vectors: locales with/without encoding, with @ modifiers, semicolon lists, and embedded NULs in both affected APIs.

Poem

🐰 I hopped through code both neat and bright,
Found sneaky NULs and locales not right,
I nibble the bugs, I tidy the line,
Now CreateProcess and setlocale shine 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title 'Fix test_subprocess and locale' accurately reflects the main changes: runtime validation additions to CreateProcess for null bytes and Windows-specific locale encoding validation.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.