Commit 407a473
committed
gh-106287: do not write objects after encountering an unmarshalling error
Writing out an object may involve a slot lookup, which is not safe to do with
an exception raised. In debug mode an assertion failure will occur if this
happens. To avoid assertion failures, and possibly more subtle problems the
assertion is there to prevent, skip attempts to write an object after an error.
Note the unmarshal writing code won't raise an exception itself, however the
set writing code calls back into the top-level unmarshal function (see
gh-78903), which will check for failures and raises an exception. Once that
happens it is not safe to continue writing further objects.
Note also that some data may still be written even after an error occurred and
an exception has been raised: code objects write objects and longs, and the
latter will be written unconditionally, even if the former fails. This
shouldn't cause a problem as it is documented that "garbage data will also be
written to the file" in such cases, and the top-level function will handle and
report the error appropriately.
Add a test case to cover the various different object types which could trigger
such failures.1 parent 815061c commit 407a473
2 files changed
+26
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
411 | 430 | | |
412 | 431 | | |
413 | 432 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
431 | 431 | | |
432 | 432 | | |
433 | 433 | | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
434 | 437 | | |
435 | 438 | | |
436 | 439 | | |
| |||
750 | 753 | | |
751 | 754 | | |
752 | 755 | | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
753 | 760 | | |
754 | 761 | | |
755 | 762 | | |
| |||
0 commit comments