Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c8faa35

Browse filesBrowse files
authored
pythongh-101180: Fix a bug where iso2022_jp_3 and iso2022_jp_2004 codecs read out of bounds (pythongh-111695)
1 parent ba8aa1f commit c8faa35
Copy full SHA for c8faa35

File tree

Expand file treeCollapse file tree

3 files changed

+53
-3
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+53
-3
lines changed

‎Lib/test/test_codecencodings_iso2022.py

Copy file name to clipboardExpand all lines: Lib/test/test_codecencodings_iso2022.py
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,52 @@ class Test_ISO2022_JP2(multibytecodec_support.TestBase, unittest.TestCase):
2424
(b'ab\x1BNdef', 'replace', 'abdef'),
2525
)
2626

27+
class Test_ISO2022_JP3(multibytecodec_support.TestBase, unittest.TestCase):
28+
encoding = 'iso2022_jp_3'
29+
tstring = multibytecodec_support.load_teststring('iso2022_jp')
30+
codectests = COMMON_CODEC_TESTS + (
31+
(b'ab\x1BNdef', 'replace', 'ab\x1BNdef'),
32+
(b'\x1B$(O\x2E\x23\x1B(B', 'strict', '\u3402' ),
33+
(b'\x1B$(O\x2E\x22\x1B(B', 'strict', '\U0002000B' ),
34+
(b'\x1B$(O\x24\x77\x1B(B', 'strict', '\u304B\u309A'),
35+
(b'\x1B$(P\x21\x22\x1B(B', 'strict', '\u4E02' ),
36+
(b'\x1B$(P\x7E\x76\x1B(B', 'strict', '\U0002A6B2' ),
37+
('\u3402', 'strict', b'\x1B$(O\x2E\x23\x1B(B'),
38+
('\U0002000B', 'strict', b'\x1B$(O\x2E\x22\x1B(B'),
39+
('\u304B\u309A', 'strict', b'\x1B$(O\x24\x77\x1B(B'),
40+
('\u4E02', 'strict', b'\x1B$(P\x21\x22\x1B(B'),
41+
('\U0002A6B2', 'strict', b'\x1B$(P\x7E\x76\x1B(B'),
42+
(b'ab\x1B$(O\x2E\x21\x1B(Bdef', 'replace', 'ab\uFFFDdef'),
43+
('ab\u4FF1def', 'replace', b'ab?def'),
44+
)
45+
xmlcharnametest = (
46+
'\xAB\u211C\xBB = \u2329\u1234\u232A',
47+
b'\x1B$(O\x29\x28\x1B(Bℜ\x1B$(O\x29\x32\x1B(B = ⟨ሴ⟩'
48+
)
49+
50+
class Test_ISO2022_JP2004(multibytecodec_support.TestBase, unittest.TestCase):
51+
encoding = 'iso2022_jp_2004'
52+
tstring = multibytecodec_support.load_teststring('iso2022_jp')
53+
codectests = COMMON_CODEC_TESTS + (
54+
(b'ab\x1BNdef', 'replace', 'ab\x1BNdef'),
55+
(b'\x1B$(Q\x2E\x23\x1B(B', 'strict', '\u3402' ),
56+
(b'\x1B$(Q\x2E\x22\x1B(B', 'strict', '\U0002000B' ),
57+
(b'\x1B$(Q\x24\x77\x1B(B', 'strict', '\u304B\u309A'),
58+
(b'\x1B$(P\x21\x22\x1B(B', 'strict', '\u4E02' ),
59+
(b'\x1B$(P\x7E\x76\x1B(B', 'strict', '\U0002A6B2' ),
60+
('\u3402', 'strict', b'\x1B$(Q\x2E\x23\x1B(B'),
61+
('\U0002000B', 'strict', b'\x1B$(Q\x2E\x22\x1B(B'),
62+
('\u304B\u309A', 'strict', b'\x1B$(Q\x24\x77\x1B(B'),
63+
('\u4E02', 'strict', b'\x1B$(P\x21\x22\x1B(B'),
64+
('\U0002A6B2', 'strict', b'\x1B$(P\x7E\x76\x1B(B'),
65+
(b'ab\x1B$(Q\x2E\x21\x1B(Bdef', 'replace', 'ab\u4FF1def'),
66+
('ab\u4FF1def', 'replace', b'ab\x1B$(Q\x2E\x21\x1B(Bdef'),
67+
)
68+
xmlcharnametest = (
69+
'\xAB\u211C\xBB = \u2329\u1234\u232A',
70+
b'\x1B$(Q\x29\x28\x1B(Bℜ\x1B$(Q\x29\x32\x1B(B = ⟨ሴ⟩'
71+
)
72+
2773
class Test_ISO2022_KR(multibytecodec_support.TestBase, unittest.TestCase):
2874
encoding = 'iso2022_kr'
2975
tstring = multibytecodec_support.load_teststring('iso2022_kr')
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug where ``iso2022_jp_3`` and ``iso2022_jp_2004`` codecs read out of bounds

‎Modules/cjkcodecs/_codecs_iso2022.c

Copy file name to clipboardExpand all lines: Modules/cjkcodecs/_codecs_iso2022.c
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ ENCODER(iso2022)
207207

208208
encoded = MAP_UNMAPPABLE;
209209
for (dsg = CONFIG_DESIGNATIONS; dsg->mark; dsg++) {
210+
Py_UCS4 buf[2] = {c, 0};
210211
Py_ssize_t length = 1;
211-
encoded = dsg->encoder(codec, &c, &length);
212+
encoded = dsg->encoder(codec, buf, &length);
212213
if (encoded == MAP_MULTIPLE_AVAIL) {
213214
/* this implementation won't work for pair
214215
* of non-bmp characters. */
@@ -217,9 +218,11 @@ ENCODER(iso2022)
217218
return MBERR_TOOFEW;
218219
length = -1;
219220
}
220-
else
221+
else {
222+
buf[1] = INCHAR2;
221223
length = 2;
222-
encoded = dsg->encoder(codec, &c, &length);
224+
}
225+
encoded = dsg->encoder(codec, buf, &length);
223226
if (encoded != MAP_UNMAPPABLE) {
224227
insize = length;
225228
break;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.