Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
2ab07f01
Kaydet (Commit)
2ab07f01
authored
Haz 23, 2013
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
(Merge 3.3) Issue #18137: Detect integer overflow on precision in
float.__format__() and complex.__format__().
üst
c6ebd16a
2f084ecf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
2 deletions
+34
-2
test_format.py
Lib/test/test_format.py
+17
-0
NEWS
Misc/NEWS
+3
-0
formatter_unicode.c
Python/formatter_unicode.c
+14
-2
No files found.
Lib/test/test_format.py
Dosyayı görüntüle @
2ab07f01
...
@@ -331,6 +331,23 @@ class FormatTest(unittest.TestCase):
...
@@ -331,6 +331,23 @@ class FormatTest(unittest.TestCase):
def
test_main
():
def
test_main
():
support
.
run_unittest
(
FormatTest
)
support
.
run_unittest
(
FormatTest
)
def
test_precision
(
self
):
INT_MAX
=
2147483647
f
=
1.2
self
.
assertEqual
(
format
(
f
,
".0f"
),
"1"
)
self
.
assertEqual
(
format
(
f
,
".3f"
),
"1.200"
)
with
self
.
assertRaises
(
ValueError
)
as
cm
:
format
(
f
,
".
%
sf"
%
(
INT_MAX
+
1
))
self
.
assertEqual
(
str
(
cm
.
exception
),
"precision too big"
)
c
=
complex
(
f
)
self
.
assertEqual
(
format
(
f
,
".0f"
),
"1"
)
self
.
assertEqual
(
format
(
f
,
".3f"
),
"1.200"
)
with
self
.
assertRaises
(
ValueError
)
as
cm
:
format
(
f
,
".
%
sf"
%
(
INT_MAX
+
1
))
self
.
assertEqual
(
str
(
cm
.
exception
),
"precision too big"
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
Misc/NEWS
Dosyayı görüntüle @
2ab07f01
...
@@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1?
...
@@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1?
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #18137: Detect integer overflow on precision in float.__format__()
and complex.__format__().
- Issue #15767: Introduce ModuleNotFoundError which is raised when a module
- Issue #15767: Introduce ModuleNotFoundError which is raised when a module
could not be found.
could not be found.
...
...
Python/formatter_unicode.c
Dosyayı görüntüle @
2ab07f01
...
@@ -982,7 +982,7 @@ format_float_internal(PyObject *value,
...
@@ -982,7 +982,7 @@ format_float_internal(PyObject *value,
Py_ssize_t
n_total
;
Py_ssize_t
n_total
;
int
has_decimal
;
int
has_decimal
;
double
val
;
double
val
;
Py_ssize_t
precision
=
format
->
precision
;
Py_ssize_t
precision
;
Py_ssize_t
default_precision
=
6
;
Py_ssize_t
default_precision
=
6
;
Py_UCS4
type
=
format
->
type
;
Py_UCS4
type
=
format
->
type
;
int
add_pct
=
0
;
int
add_pct
=
0
;
...
@@ -999,6 +999,12 @@ format_float_internal(PyObject *value,
...
@@ -999,6 +999,12 @@ format_float_internal(PyObject *value,
from a hard-code pseudo-locale */
from a hard-code pseudo-locale */
LocaleInfo
locale
=
STATIC_LOCALE_INFO_INIT
;
LocaleInfo
locale
=
STATIC_LOCALE_INFO_INIT
;
if
(
format
->
precision
>
INT_MAX
)
{
PyErr_SetString
(
PyExc_ValueError
,
"precision too big"
);
goto
done
;
}
precision
=
(
int
)
format
->
precision
;
if
(
format
->
alternate
)
if
(
format
->
alternate
)
flags
|=
Py_DTSF_ALT
;
flags
|=
Py_DTSF_ALT
;
...
@@ -1132,7 +1138,7 @@ format_complex_internal(PyObject *value,
...
@@ -1132,7 +1138,7 @@ format_complex_internal(PyObject *value,
Py_ssize_t
n_im_total
;
Py_ssize_t
n_im_total
;
int
re_has_decimal
;
int
re_has_decimal
;
int
im_has_decimal
;
int
im_has_decimal
;
Py_ssize_t
precision
=
format
->
precision
;
int
precision
;
Py_ssize_t
default_precision
=
6
;
Py_ssize_t
default_precision
=
6
;
Py_UCS4
type
=
format
->
type
;
Py_UCS4
type
=
format
->
type
;
Py_ssize_t
i_re
;
Py_ssize_t
i_re
;
...
@@ -1160,6 +1166,12 @@ format_complex_internal(PyObject *value,
...
@@ -1160,6 +1166,12 @@ format_complex_internal(PyObject *value,
from a hard-code pseudo-locale */
from a hard-code pseudo-locale */
LocaleInfo
locale
=
STATIC_LOCALE_INFO_INIT
;
LocaleInfo
locale
=
STATIC_LOCALE_INFO_INIT
;
if
(
format
->
precision
>
INT_MAX
)
{
PyErr_SetString
(
PyExc_ValueError
,
"precision too big"
);
goto
done
;
}
precision
=
(
int
)
format
->
precision
;
/* Zero padding is not allowed. */
/* Zero padding is not allowed. */
if
(
format
->
fill_char
==
'0'
)
{
if
(
format
->
fill_char
==
'0'
)
{
PyErr_SetString
(
PyExc_ValueError
,
PyErr_SetString
(
PyExc_ValueError
,
...
...
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