gh-155295: Avoid crash de-instrumenting malformed code objects - #155296
gh-155295: Avoid crash de-instrumenting malformed code objects#155296taegyunkim wants to merge 2 commits into
Conversation
463d599 to
aa742b4
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aa742b4cd3
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
https://www.githubstatus.com/incidents/qcvjkzcs7j74 incident going on with GH actions :( |
|
We don't want to avoid those crashes. We don't and won't protect against wrong instrumented code. |
|
Thanks for quick response! |
Prevent
_PyCode_GetCode()from dereferencing missing monitoring data when a malformed code object containsINSTRUMENTED_LINEorINSTRUMENTED_INSTRUCTION.Origin and AI assistance
This failure was initially identified while reviewing production crash logs available to Datadog. The investigation, reproducer, implementation, tests, and this PR write-up were produced primarily with GPT-5.6 Sol (high), with human direction, review, and local validation.
deopt_code()now validates the opcode-specific monitoring array before calling_Py_GetBaseCodeUnit(). It raisesSystemErrorand leaves the bytecode cache empty when the code object's instrumentation state is inconsistent.PyCode_GetCode()documents that it returnsNULLwith an exception set on error. Because the new consistency check adds a non-allocation failure path, the marshal writer now preserves an exception already set by_PyCode_GetCode()rather than replacing it withMemoryError.The regression test uses
CodeType.replace()to create the malformed state in a subprocess. Without the original fix, both instrumented opcodes terminate the subprocess withSIGSEGV. The test covers directcode.co_codeaccess andmarshal.dumps(code).Validation:
./python -m test test_code -m test_co_code_with_invalid_monitoring_data --verbose./python -m test -j3 test_code test_marshal test_dis./python -m test -R 3:3 test_code -m test_co_code_with_invalid_monitoring_dataPATH=/usr/bin:/bin:/usr/sbin:/sbin ./python -m test -j12: 50,379 tests executed, 470 test files passed, 3,449 tests skipped, no failuresmake patchcheck