Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c5db9239
Commit
c5db9239
authored
Jul 12, 2007
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch #1673759: add a missing overflow check when formatting floats
with %G. (backport from rev. 56298)
parent
fea72f7c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
5 deletions
+24
-5
Lib/test/test_format.py
Lib/test/test_format.py
+17
-3
Misc/NEWS
Misc/NEWS
+3
-0
Objects/stringobject.c
Objects/stringobject.c
+2
-1
Objects/unicodeobject.c
Objects/unicodeobject.c
+2
-1
No files found.
Lib/test/test_format.py
View file @
c5db9239
...
...
@@ -9,6 +9,7 @@ maxsize = MAX_Py_ssize_t
# test on unicode strings as well
overflowok
=
1
overflowrequired
=
0
def
testformat
(
formatstr
,
args
,
output
=
None
):
if
verbose
:
...
...
@@ -25,11 +26,16 @@ def testformat(formatstr, args, output=None):
if
verbose
:
print
'overflow (this is fine)'
else
:
if
o
utput
and
result
!=
output
:
if
o
verflowrequired
:
if
verbose
:
print
'no'
print
"%s %% %s == %s != %s"
%
\
(
repr
(
formatstr
),
repr
(
args
),
repr
(
result
),
repr
(
output
))
print
"overflow expected on %s %% %s"
%
\
(
repr
(
formatstr
),
repr
(
args
))
elif
output
and
result
!=
output
:
if
verbose
:
print
'no'
print
"%s %% %s == %s != %s"
%
\
(
repr
(
formatstr
),
repr
(
args
),
repr
(
result
),
repr
(
output
))
else
:
if
verbose
:
print
'yes'
...
...
@@ -57,6 +63,14 @@ testboth("%#.*g", (110, -1.e+100/3.))
# test some ridiculously large precision, expect overflow
testboth
(
'%12.*f'
,
(
123456
,
1.0
))
# check for internal overflow validation on length of precision
overflowrequired
=
1
testboth
(
"%#.*g"
,
(
110
,
-
1.e+100
/
3.
))
testboth
(
"%#.*G"
,
(
110
,
-
1.e+100
/
3.
))
testboth
(
"%#.*f"
,
(
110
,
-
1.e+100
/
3.
))
testboth
(
"%#.*F"
,
(
110
,
-
1.e+100
/
3.
))
overflowrequired
=
0
# Formatting of long integers. Overflow is not ok
overflowok
=
0
testboth
(
"%x"
,
10L
,
"a"
)
...
...
Misc/NEWS
View file @
c5db9239
...
...
@@ -12,6 +12,9 @@ What's New in Python 2.5.2c1?
Core and builtins
-----------------
- Patch #1673759: add a missing overflow check when formatting floats
with %G.
- Patch #1733960: Allow T_LONGLONG to accept ints.
- Prevent expandtabs() on string and unicode objects from causing a segfault
...
...
Objects/stringobject.c
View file @
c5db9239
...
...
@@ -4188,7 +4188,8 @@ formatfloat(char *buf, size_t buflen, int flags,
always given), therefore increase the length by one.
*/
if
((
type
==
'g'
&&
buflen
<=
(
size_t
)
10
+
(
size_t
)
prec
)
||
if
(((
type
==
'g'
||
type
==
'G'
)
&&
buflen
<=
(
size_t
)
10
+
(
size_t
)
prec
)
||
(
type
==
'f'
&&
buflen
<=
(
size_t
)
53
+
(
size_t
)
prec
))
{
PyErr_SetString
(
PyExc_OverflowError
,
"formatted float is too long (precision too large?)"
);
...
...
Objects/unicodeobject.c
View file @
c5db9239
...
...
@@ -7290,7 +7290,8 @@ formatfloat(Py_UNICODE *buf,
always given), therefore increase the length by one.
*/
if
((
type
==
'g'
&&
buflen
<=
(
size_t
)
10
+
(
size_t
)
prec
)
||
if
(((
type
==
'g'
||
type
==
'G'
)
&&
buflen
<=
(
size_t
)
10
+
(
size_t
)
prec
)
||
(
type
==
'f'
&&
buflen
<=
(
size_t
)
53
+
(
size_t
)
prec
))
{
PyErr_SetString
(
PyExc_OverflowError
,
"formatted float is too long (precision too large?)"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment