diff options
author | Eli Bendersky <eliben@gmail.com> | 2013-05-25 12:27:10 (GMT) |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2013-05-25 12:27:10 (GMT) |
commit | 7b3022f24f4bb8c64d02e103de3168e96729bdc2 (patch) | |
tree | 1d027a6e109d195fe7c6a1b3662ea4618c6fcb28 /Modules/_elementtree.c | |
parent | 19fef69b752d5a1e836ba5b552a8e68592503852 (diff) | |
parent | 6dc32b34ddfba0ddb990cbbb77cf8803879d20f9 (diff) | |
download | cpython-7b3022f24f4bb8c64d02e103de3168e96729bdc2.zip cpython-7b3022f24f4bb8c64d02e103de3168e96729bdc2.tar.gz cpython-7b3022f24f4bb8c64d02e103de3168e96729bdc2.tar.bz2 |
Issue #13612: handle unknown encodings without a buffer overflow.
This affects pyexpat and _elementtree. PyExpat_CAPI now exposes a new
function - DefaultUnknownEncodingHandler.
Based on a patch by Serhiy Storchaka.
Diffstat (limited to 'Modules/_elementtree.c')
-rw-r--r-- | Modules/_elementtree.c | 43 |
1 files changed, 1 insertions, 42 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 0d86886..377e88e 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -3094,47 +3094,6 @@ expat_pi_handler(XMLParserObject* self, const XML_Char* target_in, } } -static int -expat_unknown_encoding_handler(XMLParserObject *self, const XML_Char *name, - XML_Encoding *info) -{ - PyObject* u; - unsigned char s[256]; - int i; - void *data; - unsigned int kind; - - memset(info, 0, sizeof(XML_Encoding)); - - for (i = 0; i < 256; i++) - s[i] = i; - - u = PyUnicode_Decode((char*) s, 256, name, "replace"); - if (!u) - return XML_STATUS_ERROR; - if (PyUnicode_READY(u)) - return XML_STATUS_ERROR; - - if (PyUnicode_GET_LENGTH(u) != 256) { - Py_DECREF(u); - return XML_STATUS_ERROR; - } - - kind = PyUnicode_KIND(u); - data = PyUnicode_DATA(u); - for (i = 0; i < 256; i++) { - Py_UCS4 ch = PyUnicode_READ(kind, data, i); - if (ch != Py_UNICODE_REPLACEMENT_CHARACTER) - info->map[i] = ch; - else - info->map[i] = -1; - } - - Py_DECREF(u); - - return XML_STATUS_OK; -} - /* -------------------------------------------------------------------- */ static PyObject * @@ -3236,7 +3195,7 @@ xmlparser_init(PyObject *self, PyObject *args, PyObject *kwds) ); EXPAT(SetUnknownEncodingHandler)( self_xp->parser, - (XML_UnknownEncodingHandler) expat_unknown_encoding_handler, NULL + EXPAT(DefaultUnknownEncodingHandler), NULL ); return 0; |