FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-157325: Fix an OOB read in the `hz` incremental decoder on a trailing `~` by StanFromIreland · Pull Request #157333 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
9 changes: 9 additions & 0 deletions Lib/test/test_multibytecodec.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ def test_iso2022(self):
self.assertRaises(UnicodeDecodeError, decoder.decode, b'', True)
self.assertEqual(decoder.decode(b'B@$'), '\u4e16')

def test_hz_keep_buffer(self):
# A trailing '~' shouldn't read past the end of the input.
decoder = codecs.getincrementaldecoder('hz')()
self.assertEqual(decoder.decode(b'~'), '')
self.assertRaises(UnicodeDecodeError, decoder.decode, b'', True)
self.assertEqual(decoder.decode(b'~'), '~')
self.assertEqual(decoder.decode(b'~'), '')
self.assertEqual(decoder.decode(b'\n', True), '')

def test_decode_unicode(self):
# Trying to decode a unicode string should raise a TypeError
for enc in ALL_CJKENCODINGS:
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix an out-of-bounds read in the ``hz`` incremental decoder when the input
ends with ``~``.
2 changes: 1 addition & 1 deletion Modules/cjkcodecs/_codecs_cn.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,9 @@ DECODER(hz)
Py_UCS4 decoded;

if (c == '~') {
REQUIRE_INBUF(2);
unsigned char c2 = INBYTE2;

REQUIRE_INBUF(2);
if (c2 == '~' && state->c[CN_STATE_OFFSET] == 0)
OUTCHAR('~');
else if (c2 == '{' && state->c[CN_STATE_OFFSET] == 0)
Expand Down
Loading

Back | FazBrowse Home | New Git URL