-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-106287: do not write objects after an unmarshalling error #132715
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
Changes from 2 commits
407a473
b77cd2d
dc52961
f410a39
329c6e2
d628714
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Skip writing objects during marshalling once a failure has occurred. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -431,6 +431,9 @@ w_object(PyObject *v, WFILE *p) | |
| { | ||
| char flag = '\0'; | ||
|
|
||
| if (p->error != WFERR_OK) | ||
| return; | ||
|
duaneg marked this conversation as resolved.
Outdated
|
||
|
|
||
| p->depth++; | ||
|
|
||
| if (p->depth > MAX_MARSHAL_STACK_DEPTH) { | ||
|
|
@@ -750,6 +753,10 @@ PyMarshal_WriteLongToFile(long x, FILE *fp, int version) | |
| w_flush(&wf); | ||
| } | ||
|
|
||
| /* TODO: Contrary to its documentation, this function does NOT set an error on | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, those functions set errors as appropriate, apologies for being unclear. Various other error conditions are correctly reported, too. However unmarshallable objects like in this issue are not. AIUI they should raise a The problem is the errors are recorded in This can be reproduced with I can reword or just drop the comment, whatever you prefer. Maybe something like, "TODO: this function silently ignores some failures due to unmarshallable objects"? I'd be happy to just fix it, for that matter, but I wasn't sure whether it would be considered worth the churn. Now I look at that code again, I note the paths that currently do raise exceptions while writing objects are going to have them overwritten by that error handling code anyway. That's a shame, since they give specifics like "bad marshal data (unnormalized long data)" instead of a generic "unmarshallable object" message. Perhaps we shouldn't raise an exception if there's already one raised? |
||
| * failure. It is not used internally except from test code, where this doesn't | ||
| * matter, but this discrepancy might cause problems for any external code | ||
| * using it. */ | ||
| void | ||
| PyMarshal_WriteObjectToFile(PyObject *x, FILE *fp, int version) | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.