changeset: 96920:35a6fe0e2b27 branch: 3.4 parent: 96910:4c8cb603ab42 user: Victor Stinner date: Thu Jul 16 22:17:31 2015 +0200 files: Lib/test/multibytecodec_support.py Misc/NEWS Modules/cjkcodecs/multibytecodec.c description: Closes #23247: Fix a crash in the StreamWriter.reset() of CJK codecs diff -r 4c8cb603ab42 -r 35a6fe0e2b27 Lib/test/multibytecodec_support.py --- a/Lib/test/multibytecodec_support.py Wed Jul 15 11:42:28 2015 +1200 +++ b/Lib/test/multibytecodec_support.py Thu Jul 16 22:17:31 2015 +0200 @@ -270,6 +270,13 @@ self.assertEqual(ostream.getvalue(), self.tstring[0]) + def test_streamwriter_reset_no_pending(self): + # Issue #23247: Calling reset() on a fresh StreamWriter instance + # (without pending data) must not crash + stream = BytesIO() + writer = self.writer(stream) + writer.reset() + class TestBase_Mapping(unittest.TestCase): pass_enctest = [] diff -r 4c8cb603ab42 -r 35a6fe0e2b27 Misc/NEWS --- a/Misc/NEWS Wed Jul 15 11:42:28 2015 +1200 +++ b/Misc/NEWS Thu Jul 16 22:17:31 2015 +0200 @@ -66,6 +66,8 @@ Library ------- +- Issue #23247: Fix a crash in the StreamWriter.reset() of CJK codecs. + - Issue #18622: unittest.mock.mock_open().reset_mock would recurse infinitely. Patch from Nicola Palumbo and Laurent De Buyst. diff -r 4c8cb603ab42 -r 35a6fe0e2b27 Modules/cjkcodecs/multibytecodec.c --- a/Modules/cjkcodecs/multibytecodec.c Wed Jul 15 11:42:28 2015 +1200 +++ b/Modules/cjkcodecs/multibytecodec.c Thu Jul 16 22:17:31 2015 +0200 @@ -1629,6 +1629,9 @@ { PyObject *pwrt; + if (!self->pending) + Py_RETURN_NONE; + pwrt = multibytecodec_encode(self->codec, &self->state, self->pending, NULL, self->errors, MBENC_FLUSH | MBENC_RESET);