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
d42f60ed
Kaydet (Commit)
d42f60ed
authored
Mar 31, 2014
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
fix overflow detection of strop.expandtabs
üst
18fc4934
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
13 deletions
+24
-13
test_strop.py
Lib/test/test_strop.py
+6
-0
NEWS
Misc/NEWS
+3
-0
stropmodule.c
Modules/stropmodule.c
+15
-13
No files found.
Lib/test/test_strop.py
Dosyayı görüntüle @
d42f60ed
...
...
@@ -4,6 +4,7 @@ warnings.filterwarnings("ignore", "strop functions are obsolete;",
r'test.test_strop|unittest'
)
import
strop
import
unittest
import
sys
from
test
import
test_support
...
...
@@ -115,6 +116,11 @@ class StropFunctionTestCase(unittest.TestCase):
strop
.
uppercase
strop
.
whitespace
@unittest.skipUnless
(
sys
.
maxsize
==
2147483647
,
"only for 32-bit"
)
def
test_expandtabs_overflow
(
self
):
s
=
'
\t\n
'
*
0x10000
+
'A'
*
0x1000000
self
.
assertRaises
(
OverflowError
,
strop
.
expandtabs
,
s
,
0x10001
)
@test_support.precisionbigmemtest
(
size
=
test_support
.
_2G
-
1
,
memuse
=
5
)
def
test_stropjoin_huge_list
(
self
,
size
):
a
=
"A"
*
size
...
...
Misc/NEWS
Dosyayı görüntüle @
d42f60ed
...
...
@@ -40,6 +40,9 @@ Core and Builtins
Library
-------
-
Fix
possible
overflow
bug
in
strop
.
expandtabs
.
You
shouldn
't be using this
module!
- Issue #20145: `assertRaisesRegex` now raises a TypeError if the second
argument is not a string or compiled regex.
...
...
Modules/stropmodule.c
Dosyayı görüntüle @
d42f60ed
...
...
@@ -593,7 +593,7 @@ strop_expandtabs(PyObject *self, PyObject *args)
char
*
e
;
char
*
p
;
char
*
q
;
Py_ssize_t
i
,
j
,
old_j
;
Py_ssize_t
i
,
j
;
PyObject
*
out
;
char
*
string
;
Py_ssize_t
stringlen
;
...
...
@@ -610,30 +610,29 @@ strop_expandtabs(PyObject *self, PyObject *args)
}
/* First pass: determine size of output string */
i
=
j
=
old_j
=
0
;
/* j: current column; i: total of previous lines */
i
=
j
=
0
;
/* j: current column; i: total of previous lines */
e
=
string
+
stringlen
;
for
(
p
=
string
;
p
<
e
;
p
++
)
{
if
(
*
p
==
'\t'
)
{
j
+=
tabsize
-
(
j
%
tabsize
);
if
(
old_j
>
j
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"new string is too long"
);
return
NULL
;
}
old_j
=
j
;
Py_ssize_t
incr
=
tabsize
-
(
j
%
tabsize
);
if
(
j
>
PY_SSIZE_T_MAX
-
incr
)
goto
overflow
;
j
+=
incr
;
}
else
{
if
(
j
>
PY_SSIZE_T_MAX
-
1
)
goto
overflow
;
j
++
;
if
(
*
p
==
'\n'
)
{
if
(
i
>
PY_SSIZE_T_MAX
-
j
)
goto
overflow
;
i
+=
j
;
j
=
0
;
}
}
}
if
((
i
+
j
)
<
0
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"new string is too long"
);
return
NULL
;
}
if
(
i
>
PY_SSIZE_T_MAX
-
j
)
goto
overflow
;
/* Second pass: create output string and fill it */
out
=
PyString_FromStringAndSize
(
NULL
,
i
+
j
);
...
...
@@ -658,6 +657,9 @@ strop_expandtabs(PyObject *self, PyObject *args)
}
return
out
;
overflow:
PyErr_SetString
(
PyExc_OverflowError
,
"result is too long"
);
return
NULL
;
}
...
...
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