summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2013-08-04 13:09:49 (GMT)
committerEli Bendersky <eliben@gmail.com>2013-08-04 13:09:49 (GMT)
commitb67170114949f13c1eacf6d58a06482bb7b78dd0 (patch)
tree8c81c6d831745a521a9a86126876b7736c96938b /Modules
parent06fbac5ea0aaa30020b87b7abe6a094d65bdcd89 (diff)
downloadcpython-b67170114949f13c1eacf6d58a06482bb7b78dd0.zip
cpython-b67170114949f13c1eacf6d58a06482bb7b78dd0.tar.gz
cpython-b67170114949f13c1eacf6d58a06482bb7b78dd0.tar.bz2
Issue #13612: Fix a buffer overflow in case of a multi-byte encoding.
This is a belated backport of f7b47fb30169; Patch by Serhiy Storchaka.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_elementtree.c2
-rw-r--r--Modules/pyexpat.c7
2 files changed, 9 insertions, 0 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 379aa01..b9abcac 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -2427,6 +2427,8 @@ expat_unknown_encoding_handler(XMLParserObject *self, const XML_Char *name,
if (PyUnicode_GET_SIZE(u) != 256) {
Py_DECREF(u);
+ PyErr_SetString(PyExc_ValueError,
+ "multi-byte encodings are not supported");
return XML_STATUS_ERROR;
}
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index f269113..8de3fb1 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -1252,6 +1252,13 @@ PyUnknownEncodingHandler(void *encodingHandlerData,
if (_u_string == NULL)
return result;
+ if (PyUnicode_GET_SIZE(_u_string) != 256) {
+ Py_DECREF(_u_string);
+ PyErr_SetString(PyExc_ValueError,
+ "multi-byte encodings are not supported");
+ return result;
+ }
+
for (i = 0; i < 256; i++) {
/* Stupid to access directly, but fast */
Py_UNICODE c = _u_string->str[i];