Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/test/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ def test_common_format(self):
"format argument 1: too big for width")
test_exc_common('%*r', (-2**1000, 1), OverflowError,
"format argument 1: too big for width")
test_exc_common('%*r', (-maxsize - 1, 1), OverflowError,
"format argument 1: too big for width")
test_exc_common('%.*r', (2**1000, 1), OverflowError,
"format argument 1: too big for precision")
test_exc_common('%.*r', (-2**1000, 1), OverflowError,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Raise :exc:`OverflowError` when the absolute value of a dynamic printf-style
formatting width is too large.
4 changes: 4 additions & 0 deletions Objects/bytesobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,10 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
goto error;
}
if (width < 0) {
if (width == PY_SSIZE_T_MIN) {
FORMAT_ERROR(PyExc_OverflowError, "too big for width%s", "");
goto error;
}
flags |= F_LJUST;
width = -width;
}
Expand Down
4 changes: 4 additions & 0 deletions Objects/unicode_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,10 @@ unicode_format_arg_parse(struct unicode_formatter_t *ctx,
return -1;
}
if (arg->width < 0) {
if (arg->width == PY_SSIZE_T_MIN) {
FORMAT_ERROR(PyExc_OverflowError, "too big for width%s", "");
return -1;
}
arg->flags |= F_LJUST;
arg->width = -arg->width;
}
Expand Down
Loading