mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
Change the treatment of positions returned by PEP293
error handers in the Unicode codecs: Negative positions are treated as being relative to the end of the input and out of bounds positions result in an IndexError. Also update the PEP and include an explanation of this in the documentation for codecs.register_error. Fixes a small bug in iconv_codecs: if the position from the callback is negative *add* it to the size instead of substracting it. From SF patch #677429.
This commit is contained in:
parent
f7f4517fae
commit
2e0b18af30
5 changed files with 122 additions and 41 deletions
|
|
@ -247,8 +247,13 @@ errorexit_cbpad: Py_XDECREF(retobj);
|
|||
Py_DECREF(retobj);
|
||||
|
||||
if (newpos < 0)
|
||||
newpos = inputlen - newpos;
|
||||
if (newpos < 0 || newpos >= inputlen)
|
||||
newpos = inputlen + newpos;
|
||||
if (newpos < 0 || newpos > inputlen) {
|
||||
PyErr_Format(PyExc_IndexError, "position %ld from error handler"
|
||||
" out of bounds", newpos);
|
||||
goto errorexit;
|
||||
}
|
||||
if (newpos == inputlen)
|
||||
break;
|
||||
inp = inp_top + Py_UNICODE_SIZE * newpos;
|
||||
inplen = inplen_total - Py_UNICODE_SIZE * newpos;
|
||||
|
|
@ -471,8 +476,13 @@ errorexit_cbpad: Py_DECREF(retobj);
|
|||
Py_DECREF(retobj);
|
||||
|
||||
if (newpos < 0)
|
||||
newpos = inplen_total - newpos;
|
||||
if (newpos < 0 || newpos >= inplen_total)
|
||||
newpos = inplen_total + newpos;
|
||||
if (newpos < 0 || newpos > inplen_total) {
|
||||
PyErr_Format(PyExc_IndexError, "position %ld from error handler"
|
||||
" out of bounds", newpos);
|
||||
goto errorexit;
|
||||
}
|
||||
if (newpos == inplen_total)
|
||||
break;
|
||||
inp = inp_top + newpos;
|
||||
inplen = inplen_total - newpos;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue