FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] gh-159739: Reject the minimum dynamic formatting width (GH-159780) by jelle-openai · Pull Request #159931 · python/cpython · GitHub

Repository navigation

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

Filter by extension

Filter by extension .c  (2) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 2 additions & 0 deletions Lib/test/test_format.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ def test_common_format(self):
"%i format: a real number is required, not str")
test_exc_common('%i', b'1', TypeError,
"%i format: a real number is required, not bytes")
test_exc_common('%*r', (-maxsize - 1, 1), OverflowError,
"width too big")

def test_str_format(self):
testformat("%r", "\u0378", "'\\u0378'") # non printable
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,10 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
if (width == -1 && PyErr_Occurred())
goto error;
if (width < 0) {
if (width == PY_SSIZE_T_MIN) {
PyErr_SetString(PyExc_OverflowError, "width too big");
goto error;
}
flags |= F_LJUST;
width = -width;
}
Expand Down
4 changes: 4 additions & 0 deletions Objects/unicodeobject.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -15150,6 +15150,10 @@ unicode_format_arg_parse(struct unicode_formatter_t *ctx,
if (arg->width == -1 && PyErr_Occurred())
return -1;
if (arg->width < 0) {
if (arg->width == PY_SSIZE_T_MIN) {
PyErr_SetString(PyExc_OverflowError, "width too big");
return -1;
}
arg->flags |= F_LJUST;
arg->width = -arg->width;
}
Expand Down
Loading

Back | FazBrowse Home | New Git URL