diff -r 28f71af02b69 Objects/bytearrayobject.c --- a/Objects/bytearrayobject.c Wed Nov 13 14:17:30 2013 +0100 +++ b/Objects/bytearrayobject.c Wed Nov 13 22:14:17 2013 +0100 @@ -482,8 +482,20 @@ bytearray_setslice_linear(PyByteArrayObj } /* XXX(nnorwitz): need to verify this can't overflow! */ if (PyByteArray_Resize( - (PyObject *)self, Py_SIZE(self) + growth) < 0) + (PyObject *)self, Py_SIZE(self) + growth) < 0) { + if (growth < 0) { + if (lo == 0) { + self->ob_start += growth; + } + else { + /* memmove() removed bytes, the bytearray object cannot be + restored in its previous state. Update the size to make + at least the object consistent. */ + Py_SIZE(self) += growth; + } + } return -1; + } buf = PyByteArray_AS_STRING(self); if (growth > 0) { /* Make the place for the additional bytes */