New submission from STINNER Victor: 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 <victor.stin...@gmail.com> 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. ---------- files: bytearray_setslice_mem_error.patch keywords: patch messages: 202736 nosy: haypo, serhiy.storchaka priority: normal severity: normal status: open title: bytearray_setslice_linear() leaves the bytearray in an inconsistent state on memory allocation failure versions: Python 3.4 Added file: http://bugs.python.org/file32593/bytearray_setslice_mem_error.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue19568> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com