Repository navigation
Support Python single-byte codecs in pyexpat - #9938
Conversation
Resolve validated Expat-style codec maps lazily across threaded and synchronous readers, preserve encoding callbacks and raw byte offsets, and enable the related canonical XML tests. Assisted-by: Codex:unspecified
|
Caution Review failedThe pull request is closed.
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. |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/xml dependencies:
dependent tests: (39 tests)
[x] lib: cpython/Lib/xmlrpc dependencies:
dependent tests: (4 tests)
Legend:
|
Remove three now-passing expected-failure markers and make the custom codec search callback return None explicitly for unrelated names. Assisted-by: Codex:unspecified
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 25cc0ba0f0
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if !unicode_input | ||
| && self.encoding.is_none() | ||
| && !self.declaration.read().complete | ||
| && !isfinal |
There was a problem hiding this comment.
Keep pending declaration accumulation linear
When a declaration is streamed in small chunks, this condition now retains input until ?>, rather than only retaining the initial encoding-detection bytes. Each subsequent call moves the accumulated vector into input with mem::take, then copies the entire vector back through initial.extend_from_slice(&input). Consequently, a valid declaration containing a long whitespace run before ?> incurs quadratic copying and repeated allocations, including for ordinary UTF-8 documents that previously used the incremental reader. Preserve the owned pending buffer between calls without copying its full contents so a large or attacker-controlled declaration cannot cause this CPU amplification.
Useful? React with 👍 / 👎.
Summary
Support Python single-byte text codecs in
pyexpat, including the ISO-8859, Windows code-page, KOI8 and Mac codec families exercised by CPython 3.15.2.This is independent of #9662's DTD/entity work and does not implement missing namespace, DTD, external-entity or amplification-accounting features.
Validation
test_pyexpat test_xml_etree test_xml_etree_c test_sax test_minidom test_plistlib: 979 tests, 36 skips, success (remaining unrelated expected failures retained).stdlib_xml.pysnippet passes on RustPython and CPython 3.15.2.cargo test -p rustpython-stdlib --lib: 64 passed, 0 failed or ignored.Exact CPython diagnostic parity is not claimed: existing event positions and mixed UTF-16-header/single-byte-body column behavior still differ. No synthetic markup or test weakening hides those limitations. Windows/macOS/WASI execution and C-API tests have not been performed locally; C-API work is deferred.
AI disclosure: implementation, review and validation were assisted by OpenAI Codex; the exact model identifier is unavailable in this session. Maintainer review remains pending.
CI follow-up
The first head exposed three additional XML-RPC encoding XPASS cases on Linux, macOS and Windows. Their obsolete expected-failure markers are removed in
25cc0ba; all 94 XML-RPC tests pass locally with walltime resources enabled. The updated XML snippet passes both RustPython and CPython 3.15.2 through the pytest harness (2 passed). The review-bot suggestion to return None explicitly for unrecognized codec names is addressed.The first Windows run also failed the unrelated asyncio SSL shutdown/backpressure test with “the transport never paused writing”, including its retry. This is not claimed fixed by the XML change; a separate investigation is underway. Checks after failed Python suites were skipped. Rust tests, Clippy, Miri and WASI checks passed on the first head. CodSpeed's benchmark build/execution and pyperformance were skipped, so there is no hosted performance measurement. CI for the updated head is pending.