Annotation of pkgsrc/lang/python27/patches/patch-Python_codecs.c, revision 1.1.2.2
1.1.2.2 ! tron 1: $NetBSD$
! 2:
! 3: taken from https://hg.python.org/cpython/rev/3f7519f633ed and
! 4: https://hg.python.org/cpython/rev/d1be1f355f59:
! 5:
! 6: Issue #22518: Fixed integer overflow issues in "backslashreplace"
! 7: and "xmlcharrefreplace" error handlers.
! 8:
! 9: --- Python/codecs.c.orig 2014-06-30 02:05:46.000000000 +0000
! 10: +++ Python/codecs.c
! 11: @@ -558,7 +558,7 @@ PyObject *PyCodec_XMLCharRefReplaceError
! 12: Py_UNICODE *startp;
! 13: Py_UNICODE *e;
! 14: Py_UNICODE *outp;
! 15: - int ressize;
! 16: + Py_ssize_t ressize;
! 17: if (PyUnicodeEncodeError_GetStart(exc, &start))
! 18: return NULL;
! 19: if (PyUnicodeEncodeError_GetEnd(exc, &end))
! 20: @@ -566,6 +566,13 @@ PyObject *PyCodec_XMLCharRefReplaceError
! 21: if (!(object = PyUnicodeEncodeError_GetObject(exc)))
! 22: return NULL;
! 23: startp = PyUnicode_AS_UNICODE(object);
! 24: + if (end - start > PY_SSIZE_T_MAX / (2+7+1)) {
! 25: + end = start + PY_SSIZE_T_MAX / (2+7+1);
! 26: +#ifndef Py_UNICODE_WIDE
! 27: + if (0xD800 <= startp[end - 1] && startp[end - 1] <= 0xDBFF)
! 28: + end--;
! 29: +#endif
! 30: + }
! 31: e = startp + end;
! 32: for (p = startp+start, ressize = 0; p < e;) {
! 33: Py_UCS4 ch = *p++;
! 34: @@ -675,13 +682,15 @@ PyObject *PyCodec_BackslashReplaceErrors
! 35: Py_UNICODE *p;
! 36: Py_UNICODE *startp;
! 37: Py_UNICODE *outp;
! 38: - int ressize;
! 39: + Py_ssize_t ressize;
! 40: if (PyUnicodeEncodeError_GetStart(exc, &start))
! 41: return NULL;
! 42: if (PyUnicodeEncodeError_GetEnd(exc, &end))
! 43: return NULL;
! 44: if (!(object = PyUnicodeEncodeError_GetObject(exc)))
! 45: return NULL;
! 46: + if (end - start > PY_SSIZE_T_MAX / (1+1+8))
! 47: + end = start + PY_SSIZE_T_MAX / (1+1+8);
! 48: startp = PyUnicode_AS_UNICODE(object);
! 49: for (p = startp+start, ressize = 0; p < startp+end; ++p) {
! 50: #ifdef Py_UNICODE_WIDE
CVSweb <webmaster@jp.NetBSD.org>