-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix marshal recursive reference loading #8501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
youknowone
merged 4 commits into
RustPython:main
from
youknowone:fix/marshal-recursive-references
Aug 12, 2026
+366
−89
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
df83bc2
Fix marshal recursive reference loading
youknowone c8ea55d
Preserve marshal container insertion errors
youknowone 64d233f
Enable full abnormal marshal reference loop test
youknowone 7371547
Test direct marshal tuple reference loop
youknowone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 3074
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 32918
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 21839
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 37737
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 14561
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 359
🌐 Web query:
Python marshal documentation warning untrusted data marshal.loads malicious data💡 Result:
The Python documentation explicitly warns that the marshal module is not intended to be secure against erroneous or maliciously constructed data [1][2]. You should never use marshal.loads to process data received from an untrusted or unauthenticated source [1][3]. The reasons for this security warning include: 1. Internal Design: The marshal module was not designed as a general-purpose persistence or data interchange format [4][5]. Its primary purpose is to support the reading and writing of pseudo-compiled code for Python modules (.pyc files) [4][5]. 2. Lack of Security Audits: The C code responsible for unmarshalling data has not been thoroughly analyzed or audited for security vulnerabilities such as buffer overflows [4][5]. Because it was not written with security in mind, it may be susceptible to hypothetical exploits similar to those historically found in complex file format parsers [4][5]. 3. Potential for Crashes and Hangs: Maliciously crafted marshal data can trigger significant issues, including segmentation faults (crashes) or denial-of-service conditions (e.g., causing the interpreter to hang or consume excessive resources) [4][5][6]. 4. No Security Promises: Python maintainers explicitly state that they cannot make guarantees about the safety or security of the marshal data format, as it is not fuzz-tested for security and lacks the rigorous hardening expected of tools meant for untrusted input [6]. In summary, because marshal lacks the necessary security safeguards, it should be treated similarly to pickle: it is safe only when used with strictly trusted data [4][6]. If your application must handle external or untrusted data, safer formats such as JSON should be used instead [4][5].
Citations:
Bound marshal container lengths before placeholder allocation
marshal.loadspasses untrusted bytes to this decoder. List and tuple lengths are converted fromu32without a limit, and runtime placeholders allocate all elements before reading children. A truncated payload can therefore trigger excessive allocation or process termination instead of returningEof. Reject lengths that exceed a safe decode budget before creating list or tuple placeholders.🤖 Prompt for AI Agents