(Backport from r55770)
Bug #1728403: Fix a bug that CJKCodecs StreamReader hangs when it reads a file that ends with incomplete sequence and sizehint argument for .read() is specified.
This commit is contained in:
parent
c9490e2fe9
commit
60111e09a9
|
@ -136,6 +136,14 @@ class Test_IncrementalDecoder(unittest.TestCase):
|
|||
self.assertRaises(UnicodeDecodeError, decoder.decode, '', True)
|
||||
self.assertEqual(decoder.decode('B@$'), u'\u4e16')
|
||||
|
||||
class Test_StreamReader(unittest.TestCase):
|
||||
def test_bug1728403(self):
|
||||
try:
|
||||
open(TESTFN, 'w').write('\xa1')
|
||||
f = codecs.open(TESTFN, encoding='cp949')
|
||||
self.assertRaises(UnicodeDecodeError, f.read, 2)
|
||||
finally:
|
||||
os.unlink(TESTFN)
|
||||
|
||||
class Test_StreamWriter(unittest.TestCase):
|
||||
if len(u'\U00012345') == 2: # UCS2
|
||||
|
@ -223,6 +231,7 @@ def test_main():
|
|||
suite.addTest(unittest.makeSuite(Test_MultibyteCodec))
|
||||
suite.addTest(unittest.makeSuite(Test_IncrementalEncoder))
|
||||
suite.addTest(unittest.makeSuite(Test_IncrementalDecoder))
|
||||
suite.addTest(unittest.makeSuite(Test_StreamReader))
|
||||
suite.addTest(unittest.makeSuite(Test_StreamWriter))
|
||||
suite.addTest(unittest.makeSuite(Test_ISO2022))
|
||||
test_support.run_suite(suite)
|
||||
|
|
|
@ -12,6 +12,10 @@ What's New in Python 2.5.2c1?
|
|||
Library
|
||||
-------
|
||||
|
||||
- Bug #1728403: Fix a bug that CJKCodecs StreamReader hangs when it
|
||||
reads a file that ends with incomplete sequence and sizehint argument
|
||||
for .read() is specified.
|
||||
|
||||
- Bug #1730389: Have time.strptime() match spaces in a format argument with
|
||||
``\s+`` instead of ``\s*``.
|
||||
|
||||
|
|
|
@ -1214,6 +1214,8 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
|
|||
cres = NULL;
|
||||
|
||||
for (;;) {
|
||||
int endoffile;
|
||||
|
||||
if (sizehint < 0)
|
||||
cres = PyObject_CallMethod(self->stream,
|
||||
(char *)method, NULL);
|
||||
|
@ -1230,6 +1232,8 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
|
|||
goto errorexit;
|
||||
}
|
||||
|
||||
endoffile = (PyString_GET_SIZE(cres) == 0);
|
||||
|
||||
if (self->pendingsize > 0) {
|
||||
PyObject *ctr;
|
||||
char *ctrdata;
|
||||
|
@ -1257,7 +1261,7 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
|
|||
(MultibyteStatefulDecoderContext *)self, &buf))
|
||||
goto errorexit;
|
||||
|
||||
if (rsize == 0 || sizehint < 0) { /* end of file */
|
||||
if (endoffile || sizehint < 0) {
|
||||
if (buf.inbuf < buf.inbuf_end &&
|
||||
multibytecodec_decerror(self->codec, &self->state,
|
||||
&buf, self->errors, MBERR_TOOFEW))
|
||||
|
|
Loading…
Reference in New Issue