mirror of https://github.com/python/cpython
Issue #23466: Raised OverflowError if %c argument is out of range.
This commit is contained in:
parent
45ec3288d0
commit
41525e31a5
|
@ -358,12 +358,12 @@ class FormatTest(unittest.TestCase):
|
||||||
"not all arguments converted during bytes formatting")
|
"not all arguments converted during bytes formatting")
|
||||||
test_exc(b'no format', bytearray(b'1'), TypeError,
|
test_exc(b'no format', bytearray(b'1'), TypeError,
|
||||||
"not all arguments converted during bytes formatting")
|
"not all arguments converted during bytes formatting")
|
||||||
test_exc(b"%c", -1, TypeError,
|
test_exc(b"%c", -1, OverflowError,
|
||||||
"%c requires an integer in range(256) or a single byte")
|
"%c arg not in range(256)")
|
||||||
test_exc(b"%c", 256, TypeError,
|
test_exc(b"%c", 256, OverflowError,
|
||||||
"%c requires an integer in range(256) or a single byte")
|
"%c arg not in range(256)")
|
||||||
test_exc(b"%c", 2**128, TypeError,
|
test_exc(b"%c", 2**128, OverflowError,
|
||||||
"%c requires an integer in range(256) or a single byte")
|
"%c arg not in range(256)")
|
||||||
test_exc(b"%c", b"Za", TypeError,
|
test_exc(b"%c", b"Za", TypeError,
|
||||||
"%c requires an integer in range(256) or a single byte")
|
"%c requires an integer in range(256) or a single byte")
|
||||||
test_exc(b"%c", "Y", TypeError,
|
test_exc(b"%c", "Y", TypeError,
|
||||||
|
|
|
@ -496,10 +496,15 @@ byte_converter(PyObject *arg, char *p)
|
||||||
ival = PyLong_AsLongAndOverflow(iobj, &overflow);
|
ival = PyLong_AsLongAndOverflow(iobj, &overflow);
|
||||||
Py_DECREF(iobj);
|
Py_DECREF(iobj);
|
||||||
}
|
}
|
||||||
if (!overflow && 0 <= ival && ival <= 255) {
|
if (!overflow && ival == -1 && PyErr_Occurred())
|
||||||
*p = (char)ival;
|
goto onError;
|
||||||
return 1;
|
if (overflow || !(0 <= ival && ival <= 255)) {
|
||||||
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
|
"%c arg not in range(256)");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
*p = (char)ival;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
onError:
|
onError:
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
|
Loading…
Reference in New Issue