This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients serhiy.storchaka, vstinner
Date 2013-11-13.12:20:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1384345240.98.0.498941020154.issue19568@psf.upfronthosting.co.za>
In-reply-to
Content
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.stinner@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.
History
Date User Action Args
2013-11-13 12:20:40vstinnersetrecipients: + vstinner, serhiy.storchaka
2013-11-13 12:20:40vstinnersetmessageid: <1384345240.98.0.498941020154.issue19568@psf.upfronthosting.co.za>
2013-11-13 12:20:40vstinnerlinkissue19568 messages
2013-11-13 12:20:40vstinnercreate