Skip to content

Fix Windows runtime validation and 32-bit string size overflows - #9412

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowone:windows-runtime-followups
Oct 28, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowone:windows-runtime-followups

Conversation

@youknowone

@youknowone youknowone commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow up the Windows runtime fixes in #9406, without C API, ctypes, PyO3, dependency, or CI changes.

  • Reject WSARecvFromInto requests larger than their writable buffer before starting I/O.
  • Match CPython's spawnv argument TypeError while preserving embedded-NUL ValueError and other conversion exceptions.
  • Check replacement, tab-expansion, and string-join result sizes before allocation. This fixes capacity-overflow panics and oversized-allocation aborts reproduced in an actual 32-bit Windows process. Fallible allocation is used for tab expansion and string join.
  • Add Rust regression tests for length arithmetic, receive validation, and spawnv exceptions. Remove the now-passing Windows expected-failure markers; the redundant socket-test override is removed so the unchanged inherited test runs normally.

Rebased onto upstream/main at 058bebf.

Validation

  • Windows x64: cargo test --workspace --exclude rustpython_wasm --exclude rustpython-venvlauncher --exclude rustpython-capi passed after rebase.
  • Windows x64: workspace/all-targets Clippy with the same exclusions and -D warnings passed. Only the existing linker-messages warning remains (not governed by -D warnings). Separate crates/capi Clippy also passed.
  • Actual i686-pc-windows-msvc interpreter: test_str test_bytes test_struct test_array test_os test_winapi test_subprocess passed (9 expanded test files; reported run=2,357, skipped=589).
  • Windows x64 related regression modules passed, including asyncio low-level sockets, os, subprocess, winapi, msvcrt, signal, dbm, and interpreter-pool tests (10 expanded files).
  • Existing skipped replacement-overflow tests were also invoked without their skip wrappers at runtime for str, bytes, and bytearray; all passed on x86. Their source skip decorators are unchanged.
  • Formatting and all applicable pre-commit hooks passed; focused pre-commit review found no blockers.

C API tests were attempted separately but remain blocked by missing-symbol link errors outside this PR; no C API fixes are included. The separately reproduced Windows subnormal math.remainder issue originates in the external pymath dependency and is also excluded. This PR does not claim that every Windows incompatibility is resolved.

AI assistance

Codex assisted with implementation, investigation, testing, review, and this PR description. Runtime checks were executed on Windows x64 and x86; no human review is claimed.

Summary by CodeRabbit

  • Bug Fixes
    • Oversized receive requests are rejected before I/O begins.
    • String and byte operations now report overflow or allocation failures instead of proceeding with invalid or unavailable output sizes.
    • Tab expansion handles zero tab stops and line breaks consistently.
    • On MSVC, invalid path-like arguments to spawnv receive a clearer error; embedded-null errors remain unchanged.

Validate overlapped receive buffer sizes before starting I/O and preserve spawnv non-TypeError argument failures. Check replacement, tab expansion, and string join sizes before allocation to avoid 32-bit capacity overflows.

Implementation, regression investigation, and validation assisted by Codex.

Assisted-by: Codex:GPT-5
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-28T01:39:55.348699Z
We couldn’t complete this review. Comment @codex review to try again.
bd68b55 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 058bebf and bd68b55.

Files ignored due to path filters: 2
  • Lib/test/test_asyncio/test_sock_lowlevel.py is excluded by !Lib/**
  • Lib/test/test_os/test_os.py is excluded by !Lib/**
Files selected for processing: 8
  • crates/common/src/str.rs
  • crates/stdlib/src/overlapped.rs
  • crates/vm/src/anystr.rs
  • crates/vm/src/builtins/bytearray.rs
  • crates/vm/src/builtins/bytes.rs
  • crates/vm/src/builtins/str.rs
  • crates/vm/src/bytes_inner.rs
  • crates/vm/src/stdlib/nt.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

The changes add checked size calculations and fallible allocation handling for string and bytes operations. They also update tab expansion, validate overlapped receive buffer sizes, and adjust MSVC spawnv argument error mapping.

Changes: String and bytes sizing

Layer / File(s) Summary
Checked length calculations
crates/vm/src/anystr.rs
New helpers calculate replacement and tab-expansion lengths with checked arithmetic. Tests cover overflow, size limits, and tab-column behavior.
Tab expansion
crates/common/src/str.rs, crates/vm/src/anystr.rs, crates/vm/src/builtins/{bytearray.rs,bytes.rs,str.rs}, crates/vm/src/bytes_inner.rs
The common string function appends expansion to a supplied buffer. String and bytes expansion check output capacity and propagate overflow or allocation errors through their builtin methods.
Replacement and join sizing
crates/vm/src/builtins/str.rs, crates/vm/src/bytes_inner.rs
String join and replacement check output sizes and allocation. Bytes replacement uses checked length calculations and propagates errors for empty-pattern replacement.

Overlapped receive validation

Layer / File(s) Summary
Receive buffer size check
crates/stdlib/src/overlapped.rs
WSARecvFromInto rejects a requested size larger than the supplied buffer before changing operation state or starting I/O. A unit test checks the error and unchanged state.

MSVC spawnv argument errors

Layer / File(s) Summary
Argument conversion and error mapping
crates/vm/src/stdlib/nt.rs
On MSVC, argv path-conversion TypeErrors use the specified argument-2 message. Other errors remain unchanged. Tests cover non-string and embedded-null arguments.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related PRs

  • RustPython/RustPython#9406: The PR description says this change follows up on its Windows runtime fixes. Both changes touch Windows runtime behavior, although they modify separate code paths.

Suggested reviewers: 1ndahous3, luantaraschi, joshuamegnauth54

Merge Risk: Minimal · up to bd68b

The changes add checked sizing and Windows input validation. The spawnv exception behavior matches CPython, and no merge-blocking defect remains identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 23.08% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely summarizes the main changes: Windows runtime validation fixes and prevention of 32-bit string-size overflows.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 23.08% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 13 functions across 8 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[x] lib: cpython/Lib/asyncio
[ ] test: cpython/Lib/test/test_asyncio (TODO: 2)

dependencies:

  • asyncio

dependent tests: (9 tests)

  • asyncio: test_asyncio test_concurrent_futures test_external_inspection test_inspect test_logging test_os test_pdb test_unittest
    • pdb: test_remote_pdb

[x] lib: cpython/Lib/os.py
[x] test: cpython/Lib/test/test_popen.py

dependencies:

  • os

dependent tests: (191 tests)

  • os: test___all__ test__osx_support test_argparse test_asdl_parser test_ast test_asyncio test_atexit test_base64 test_baseexception test_bdb test_bool test_buffer test_builtin test_bytes test_bz2 test_c_locale_coercion test_calendar test_clinic test_cmd_line test_cmd_line_script test_codecs test_compile test_compileall test_concurrent_futures test_configparser test_contextlib test_ctypes test_curses test_dbm test_dbm_dumb test_dbm_gnu test_dbm_ndbm test_dbm_sqlite3 test_decimal test_devpoll test_doctest test_dtrace test_eintr test_embed test_ensurepip test_enum test_epoll test_exception_hierarchy test_exceptions test_external_inspection test_faulthandler test_fcntl test_file_eintr test_filecmp test_fileinput test_fileutils test_float test_fnmatch test_fork1 test_fractions test_fstring test_ftplib test_future_stmt test_generated_cases test_genericalias test_genericpath test_getpass test_gettext test_glob test_graphlib test_gzip test_hash test_hashlib test_http_cookiejar test_httplib test_httpservers test_imaplib test_importlib test_inspect test_interpreters test_io test_ioctl test_json test_kqueue test_launcher test_linecache test_locale test_logging test_lzma test_mailbox test_marshal test_math test_mimetypes test_mmap test_modulefinder test_msvcrt test_multiprocessing_forkserver test_multiprocessing_main_handling test_netrc test_ntpath test_openpty test_optparse test_os test_pathlib test_pdb test_peg_generator test_perfmaps test_pkg test_pkgutil test_platform test_plistlib test_poll test_popen test_poplib test_posixpath test_profile test_profiling test_pstats test_pty test_py_compile test_pydoc test_pyexpat test_pyrepl test_random test_regrtest test_remote_pdb test_repl test_reprlib test_robotparser test_runpy test_sax test_script_helper test_selectors test_shelve test_shlex test_shutil test_signal test_site test_smtpnet test_socket test_socketserver test_sqlite3 test_ssl test_stat test_string_literals test_strptime test_structseq test_subprocess test_support test_sys test_sys_settrace test_sysconfig test_tabnanny test_tarfile test_tcl test_tempfile test_termios test_thread test_threading test_threadsignals test_time test_tkinter test_tokenize test_tools test_trace test_traceback test_tracemalloc test_tty test_turtle test_typing test_unicode_file test_unicode_file_functions test_unittest test_urllib test_urllib2 test_urllib2_localnet test_urllib2net test_urllibnet test_uuid test_venv test_wait3 test_wait4 test_wave test_webbrowser test_winapi test_winconsoleio test_winreg test_winsound test_wsgiref test_xml_etree test_xpickle test_zipfile test_zipimport test_zipimport_support test_zoneinfo test_zstd

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

@youknowone
youknowone merged commit 1ba0099 into RustPython:main Oct 28, 2026
29 checks passed
@youknowone
youknowone deleted the windows-runtime-followups branch October 28, 2026 08:29
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.

1 participant