Browse Source
bpo-35062: Fix parsing _io.IncrementalNewlineDecoder's *translate* argument. (GH-10217)
_io.IncrementalNewlineDecoder's initializer possibly assigns out-of-range
value to the bitwise struct field.
pull/10265/head
Xiang Zhang
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
13 additions and
1 deletions
-
Lib/test/test_io.py
-
Misc/NEWS.d/next/Library/2018-10-29-23-09-24.bpo-35062.dQS1ng.rst
-
Modules/_io/textio.c
|
|
|
@ -3748,6 +3748,16 @@ class IncrementalNewlineDecoderTest(unittest.TestCase): |
|
|
|
dec = self.IncrementalNewlineDecoder(None, translate=True) |
|
|
|
_check(dec) |
|
|
|
|
|
|
|
def test_translate(self): |
|
|
|
# issue 35062 |
|
|
|
for translate in (-2, -1, 1, 2): |
|
|
|
decoder = codecs.getincrementaldecoder("utf-8")() |
|
|
|
decoder = self.IncrementalNewlineDecoder(decoder, translate) |
|
|
|
self.check_newline_decoding_utf8(decoder) |
|
|
|
decoder = codecs.getincrementaldecoder("utf-8")() |
|
|
|
decoder = self.IncrementalNewlineDecoder(decoder, translate=0) |
|
|
|
self.assertEqual(decoder.decode(b"\r\r\n"), "\r\r\n") |
|
|
|
|
|
|
|
class CIncrementalNewlineDecoderTest(IncrementalNewlineDecoderTest): |
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
@ -0,0 +1,2 @@ |
|
|
|
Fix incorrect parsing of :class:`_io.IncrementalNewlineDecoder`'s |
|
|
|
*translate* argument. |
|
|
|
@ -261,7 +261,7 @@ _io_IncrementalNewlineDecoder___init___impl(nldecoder_object *self, |
|
|
|
} |
|
|
|
Py_INCREF(self->errors); |
|
|
|
|
|
|
|
self->translate = translate; |
|
|
|
self->translate = translate ? 1 : 0; |
|
|
|
self->seennl = 0; |
|
|
|
self->pendingcr = 0; |
|
|
|
|
|
|
|
|