Message202736
When bytearray_setslice_linear() is called to shrink the buffer with lo=0 and PyByteArray_Resize() fails because of a memory error, the bytearray is leaved in an inconsistent state: ob_start has been updated but not the size.
I found the issue using failmalloc: test_nonblock_pipe_write_smallbuf() of test_io does fail with an assertion error when testing the _pyio module which uses bytearray for the write buffer.
Attached patch restores the bytearray in its previous state if PyByteArray_Resize() failed.
I prefer to only fix the issue in Python 3.4 because it is unlikely and I prefer to not introduce regressions in previous Python versions.
I made a similar fix for list:
changeset: 84717:3f25a7dd8346
user: Victor Stinner <[email protected]>
date: Fri Jul 19 23:06:21 2013 +0200
files: Objects/listobject.c
description:
Issue #18408: Fix list_ass_slice(), handle list_resize() failure
I tested the patch manually by injecting a fault using gdb: list items are correctly restored on failure. |
|
| Date |
User |
Action |
Args |
| 2013-11-13 12:20:40 | vstinner | set | recipients:
+ vstinner, serhiy.storchaka |
| 2013-11-13 12:20:40 | vstinner | set | messageid: <[email protected]> |
| 2013-11-13 12:20:40 | vstinner | link | issue19568 messages |
| 2013-11-13 12:20:40 | vstinner | create | |
|