diff options
author | Walter Dörwald <walter@livinglogic.de> | 2003-01-31 17:19:08 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2003-01-31 17:19:08 (GMT) |
commit | 2e0b18af3092a24c9689f72af898083ebfd9aec7 (patch) | |
tree | 5dd08384e3560210deb41201ae3d7835899b44cd /Modules | |
parent | f7f4517faeec7a37f5ad545092252a55e0450e10 (diff) | |
download | cpython-2e0b18af3092a24c9689f72af898083ebfd9aec7.zip cpython-2e0b18af3092a24c9689f72af898083ebfd9aec7.tar.gz cpython-2e0b18af3092a24c9689f72af898083ebfd9aec7.tar.bz2 |
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.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_iconv_codec.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/Modules/_iconv_codec.c b/Modules/_iconv_codec.c index d61adbc..3f2a72a 100644 --- a/Modules/_iconv_codec.c +++ b/Modules/_iconv_codec.c @@ -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; |