Skip to content

Match mmap constructor audit ordering and argument conversion - #9489

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:py315-mmap-constructor-audit-20261030
Oct 30, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:py315-mmap-constructor-audit-20261030

Conversation

@youknowdot

@youknowdot youknowdot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Emit mmap.__new__ at CPython's platform-specific point: after argument validation/access normalization on Unix, before access/length/tag validation on Windows. Preserve requested length and propagate hook refusal before host mapping operations.
  • Convert access using getargs.c's signed-int contract (C-long conversion followed by C-int bounds), without prematurely validating its enum. Use truth testing for trackfd.
  • Restore the existing test_audit.AuditTest.test_mmap using scripts/update_lib migrate, retaining unrelated test adaptations.

Source comparison: pinned CPython new_mmap_object, Unix and Windows implementations, getargs.c signed-int conversion, and PyLong_AsLong.

No storage/locking/GC changes, global argument-converter refactor, or flush changes. The existing conditional flush-test skip remains untouched. The existing Windows Rust fixture only receives the matching constructor field types.

Validation

  • Scoped Cargo check, strict Clippy, and CLI build passed.
  • 31 finite Linux observations per engine matched pinned CPython exactly. Four successful anonymous 8-byte mappings were explicitly closed; all remaining cases were hook-refused or preflight-rejected. Count, denial, length, and closed-state assertions were enforced.
  • Normal configured commit hooks passed after a rustfmt-only retry. Canonical formatting of the preserved tested source is byte-identical to the committed source; no behavioral source change followed validation.
  • Windows-specific ordering was source-reviewed, not emulated locally. Canonical subprocess tests and whole suites were not run locally; hosted CI is pending.

AI assistance

OpenAI Codex assisted with implementation, CPython source comparison, and validation. The model version was unavailable.

Summary by CodeRabbit

  • Bug Fixes
    • Memory-mapped file access arguments now report overflow errors when values exceed supported integer bounds and ValueError for access modes outside the supported range.
    • The trackfd argument is now interpreted as a boolean on both Unix and Windows.

Emit platform-specific mmap.__new__ audit events with requested lengths and correct access semantics, use getargs-compatible access conversion and trackfd truth testing, and restore the canonical mmap audit test through update_lib.

Assisted-by: OpenAI Codex: model version unavailable
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Walkthrough

The mmap constructors now parse access through an integer argument type, convert trackfd through ArgIntoBool, and emit audit events. Unix and Windows constructors use different audit-event ordering relative to access validation.

Changes: mmap constructor behavior

Layer / File(s) Summary
Access argument parsing
crates/stdlib/src/mmap.rs
AccessArg uses Python’s index protocol, checks C long and C int bounds, and accepts access values from 0 to 3.
Platform constructor integration
crates/stdlib/src/mmap.rs
The Unix and Windows constructors use AccessArg and ArgIntoBool for access and trackfd. Unix emits the audit event after access validation; Windows emits it before access validation. The Windows test fixture uses the updated argument types.

Priority: Not assessed

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Possibly related issues

  • RustPython/RustPython issue 6839 tracks standard-library updates from CPython 3.15. This change updates mmap behavior to match CPython and relates to restoring the stated audit test.

Possibly related PRs

  • RustPython/RustPython#9406: Both changes update the mmap constructor; this change also updates access and trackfd conversion and audit-event ordering.

Suggested reviewers: youknowone

Merge Risk: Minimal · up to 2012e

No merge-blocking issue is established. Windows invalid-access audit ordering would benefit from a regression test; merging remains reasonable after normal checks pass.

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] test: cpython/Lib/test/test_sys.py (TODO: 4)
[x] test: cpython/Lib/test/test_syslog.py
[x] test: cpython/Lib/test/test_sys_setprofile.py (TODO: 1)
[x] test: cpython/Lib/test/test_sys_settrace.py
[x] test: cpython/Lib/test/test_audit.py (TODO: 15)
[x] test: cpython/Lib/test/audit-tests.py

dependencies:

dependent tests: (249 tests)

  • sys: regrtestdata test___all__ test__colorize test__locale test__osx_support test_android test_annotationlib test_argparse test_array test_asdl_parser test_ast test_asyncio test_audit test_base64 test_bdb test_bigaddrspace test_bigmem test_binascii test_bisect test_buffer test_builtin test_bytes test_bz2 test_c_locale_coercion test_calendar test_class test_clinic test_cmath test_cmd test_cmd_line test_cmd_line_script test_code test_code_module test_codeccallbacks test_codecs test_collections test_compile test_compileall test_complex test_concurrent_futures test_context test_contextlib test_coroutines test_crossinterp test_csv test_ctypes test_curses test_datetime test_dbm test_dbm_sqlite3 test_decimal test_descr test_dict test_difflib test_dis test_doctest test_docxmlrpc test_dtrace test_dynamic test_dynamicclassattribute test_email test_embed test_ensurepip test_enum test_enumerate test_eof test_epoll test_except_star test_exceptions test_external_inspection test_faulthandler test_fcntl test_file_eintr test_fileinput test_float test_fork1 test_format test_fractions test_frame test_free_threading test_frozen test_functools test_future_stmt test_gc test_generated_cases test_generators test_genericpath test_genexps test_getopt test_glob test_grammar test_gzip test_hash test_hashlib test_http_cookiejar test_httpservers test_importlib test_inspect test_int test_interpreters test_io test_ioctl test_iter test_itertools test_json test_launcher test_list test_listcomps test_locale test_logging test_long test_lzma test_mailbox test_marshal test_math test_memoryview test_metaclass test_mimetypes test_mmap test_monitoring test_msvcrt test_multibytecodec test_multiprocessing_forkserver test_multiprocessing_main_handling test_netrc test_ntpath test_numeric_tower test_opcache test_operator test_optparse test_ordered_dict test_os test_osx_env test_pathlib test_patma test_pdb test_peepholer test_perfmaps test_pickle test_pkg test_pkgutil test_platform test_plistlib test_popen test_posixpath test_print test_profile test_profiling test_property test_pty test_pwd test_py_compile test_pyclbr test_pydoc test_pyexpat test_pyrepl test_quopri test_raise test_range test_re test_readline test_regrtest test_remote_pdb test_repl test_reprlib test_resource test_runpy test_sax test_scope test_script_helper test_select test_selectors test_shutil test_signal test_site test_slice test_smtplib test_socket test_source_encoding test_sqlite3 test_ssl test_stable_abi_ctypes test_startfile test_stat test_statistics test_str test_strftime test_string_literals test_strptime test_strtod test_struct test_subprocess test_support test_sys test_sys_setprofile test_sys_settrace test_sysconfig test_syslog test_tabnanny test_tarfile test_tcl test_tempfile test_termios test_threading test_threading_local test_threadsignals test_time test_timeit test_tkinter test_tomllib test_tools test_trace test_traceback test_tracemalloc test_ttk test_tuple test_type_cache test_type_comments test_types test_typing test_unicode_file test_unicode_file_functions test_unicodedata test_unittest test_urllib test_urllib2 test_urllib2net test_urlparse test_utf8_mode test_uuid test_venv test_wait3 test_wait4 test_wave test_weakref test_webbrowser test_winconsoleio test_winreg test_with test_wsgiref test_xml_etree test_xmlrpc test_xpickle test_zipapp test_zipfile test_zipfile64 test_zipimport test_zipimport_support test_zlib

Legend:

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

@codspeed

codspeed Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing youknowdot:py315-mmap-constructor-audit-20261030 (2012e06) with main (d24ca41)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@youknowone
youknowone marked this pull request as ready for review October 30, 2026 15:17
@youknowone
youknowone enabled auto-merge (squash) October 30, 2026 15:17
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 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-30T15:19:08.560598Z
We couldn’t complete this review. Comment @codex review to try again.
2012e06 Draft marked ready
ℹ️ 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.

@youknowone
youknowone merged commit a20e9cd into RustPython:main Oct 30, 2026
30 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.

3 participants