Author: Ronan Lamy <[email protected]>
Branch: py3.6
Changeset: r97797:08277358d8fb
Date: 2019-10-16 16:48 +0100
http://bitbucket.org/pypy/pypy/changeset/08277358d8fb/
Log: Fix range checking in GB18030 decoder (bpo-29990)
diff --git a/pypy/module/_multibytecodec/src/cjkcodecs/_codecs_cn.c
b/pypy/module/_multibytecodec/src/cjkcodecs/_codecs_cn.c
--- a/pypy/module/_multibytecodec/src/cjkcodecs/_codecs_cn.c
+++ b/pypy/module/_multibytecodec/src/cjkcodecs/_codecs_cn.c
@@ -266,7 +266,9 @@
REQUIRE_INBUF(4)
c3 = IN3;
c4 = IN4;
- if (c < 0x81 || c3 < 0x81 || c4 < 0x30 || c4 > 0x39)
+ if (c < 0x81 || c > 0xFE ||
+ c3 < 0x81 || c3 > 0xFE ||
+ c4 < 0x30 || c4 > 0x39)
return 1;
c -= 0x81; c2 -= 0x30;
c3 -= 0x81; c4 -= 0x30;
diff --git a/pypy/module/_multibytecodec/test/test_c_codecs.py
b/pypy/module/_multibytecodec/test/test_c_codecs.py
--- a/pypy/module/_multibytecodec/test/test_c_codecs.py
+++ b/pypy/module/_multibytecodec/test/test_c_codecs.py
@@ -1,4 +1,5 @@
import py
+import pytest
from pypy.module._multibytecodec.c_codecs import getcodec, codecs
from pypy.module._multibytecodec.c_codecs import decode, encode
from pypy.module._multibytecodec.c_codecs import EncodeDecodeError
@@ -18,6 +19,15 @@
u = decode(c, "foobar")
assert u == "foobar"
[email protected]('undecodable', [
+ b"abc\x80\x80\xc1\xc4",
+ b"\xff\x30\x81\x30", b"\x81\x30\xff\x30", # bpo-29990
+])
+def test_decode_gb18030_error(undecodable):
+ c = getcodec("gb18030")
+ with pytest.raises(EncodeDecodeError):
+ decode(c, undecodable)
+
def test_decode_hz():
# stateful
c = getcodec("hz")
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit