summaryrefslogtreecommitdiff
path: root/Python/codecs.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-09-23 19:59:34 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2014-09-23 19:59:34 +0300
commit6c8e38ef5749e502746f55f531b0694c05ce6827 (patch)
treefc12d10c554666dc0c1fbeaf01be25b4ecc341f9 /Python/codecs.c
parent4dd73af37ac1d749a85d9384205be1929f708ce9 (diff)
parentffa0f96fe4f78f1da589bb4cbeb3493d586941aa (diff)
downloadcpython-6c8e38ef5749e502746f55f531b0694c05ce6827.tar.gz
Fixed reference leak in the "backslashreplace" error handler.
Diffstat (limited to 'Python/codecs.c')
-rw-r--r--Python/codecs.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/Python/codecs.c b/Python/codecs.c
index e584accf72..02fce29561 100644
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -929,6 +929,7 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
}
}
+#define ENC_UNKNOWN -1
#define ENC_UTF8 0
#define ENC_UTF16BE 1
#define ENC_UTF16LE 2
@@ -944,7 +945,11 @@ get_standard_encoding(const char *encoding, int *bytelength)
encoding += 3;
if (*encoding == '-' || *encoding == '_' )
encoding++;
- if (encoding[0] == '1' && encoding[1] == '6') {
+ if (encoding[0] == '8' && encoding[1] == '\0') {
+ *bytelength = 3;
+ return ENC_UTF8;
+ }
+ else if (encoding[0] == '1' && encoding[1] == '6') {
encoding += 2;
*bytelength = 2;
if (*encoding == '\0') {
@@ -983,9 +988,11 @@ get_standard_encoding(const char *encoding, int *bytelength)
}
}
}
- /* utf-8 */
- *bytelength = 3;
- return ENC_UTF8;
+ else if (strcmp(encoding, "CP_UTF8") == 0) {
+ *bytelength = 3;
+ return ENC_UTF8;
+ }
+ return ENC_UNKNOWN;
}
/* This handler is declared static until someone demonstrates
@@ -1022,6 +1029,12 @@ PyCodec_SurrogatePassErrors(PyObject *exc)
}
code = get_standard_encoding(encoding, &bytelength);
Py_DECREF(encode);
+ if (code == ENC_UNKNOWN) {
+ /* Not supported, fail with original exception */
+ PyErr_SetObject(PyExceptionInstance_Class(exc), exc);
+ Py_DECREF(object);
+ return NULL;
+ }
res = PyBytes_FromStringAndSize(NULL, bytelength*(end-start));
if (!res) {
@@ -1096,6 +1109,12 @@ PyCodec_SurrogatePassErrors(PyObject *exc)
}
code = get_standard_encoding(encoding, &bytelength);
Py_DECREF(encode);
+ if (code == ENC_UNKNOWN) {
+ /* Not supported, fail with original exception */
+ PyErr_SetObject(PyExceptionInstance_Class(exc), exc);
+ Py_DECREF(object);
+ return NULL;
+ }
/* Try decoding a single surrogate character. If
there are more, let the codec call us again. */