Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
8bbcc0cd
Commit
8bbcc0cd
authored
Apr 20, 2020
by
Sam Sneddon
Committed by
Stefan Behnel
Apr 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid integer overflow when computing unicode substring (GH-3532)
Fixes #3531.
parent
c0376241
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
9 deletions
+30
-9
Cython/Utility/StringTools.c
Cython/Utility/StringTools.c
+1
-2
tests/run/unicode_slicing.pyx
tests/run/unicode_slicing.pyx
+29
-7
No files found.
Cython/Utility/StringTools.c
View file @
8bbcc0cd
...
...
@@ -558,8 +558,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Substring(
stop
+=
length
;
else
if
(
stop
>
length
)
stop
=
length
;
length
=
stop
-
start
;
if
(
length
<=
0
)
if
(
stop
<=
start
)
return
PyUnicode_FromUnicode
(
NULL
,
0
);
#if CYTHON_PEP393_ENABLED
return
PyUnicode_FromKindAndData
(
PyUnicode_KIND
(
text
),
...
...
tests/run/unicode_slicing.pyx
View file @
8bbcc0cd
...
...
@@ -151,30 +151,52 @@ __doc__ = u"""
>>> slice_none_none(None, 2, 4)
Traceback (most recent call last):
TypeError: 'NoneType' object is not subscriptable
>>> slice_start_end(u'abcdef', SSIZE_T_MAX, SSIZE_T_MIN)
<BLANKLINE>
>>> slice_start(u'abcdef', SSIZE_T_MAX, SSIZE_T_MIN)
<BLANKLINE>
>>> slice_end(u'abcdef', SSIZE_T_MAX, SSIZE_T_MIN)
abcdef
>>> slice_all(u'abcdef', SSIZE_T_MAX, SSIZE_T_MIN)
abcdef
>>> slice_start_none(u'abcdef', SSIZE_T_MAX, SSIZE_T_MIN)
<BLANKLINE>
>>> slice_none_end(u'abcdef', SSIZE_T_MAX, SSIZE_T_MIN)
abcdef
>>> slice_none_none(u'abcdef', SSIZE_T_MAX, SSIZE_T_MIN)
abcdef
"""
cdef
extern
from
*
:
cdef
Py_ssize_t
PY_SSIZE_T_MIN
cdef
Py_ssize_t
PY_SSIZE_T_MAX
SSIZE_T_MAX
=
PY_SSIZE_T_MAX
SSIZE_T_MIN
=
PY_SSIZE_T_MIN
import
sys
if
sys
.
version_info
[
0
]
>=
3
:
__doc__
=
__doc__
.
replace
(
u"(u'"
,
u"('"
).
replace
(
u" u'"
,
u" '"
)
def
slice_start_end
(
unicode
s
,
int
i
,
in
t
j
):
def
slice_start_end
(
unicode
s
,
Py_ssize_t
i
,
Py_ssize_
t
j
):
print
(
s
[
i
:
j
])
def
slice_start
(
unicode
s
,
int
i
,
in
t
j
):
def
slice_start
(
unicode
s
,
Py_ssize_t
i
,
Py_ssize_
t
j
):
print
(
s
[
i
:])
def
slice_end
(
unicode
s
,
int
i
,
in
t
j
):
def
slice_end
(
unicode
s
,
Py_ssize_t
i
,
Py_ssize_
t
j
):
print
(
s
[:
i
])
def
slice_all
(
unicode
s
,
int
i
,
in
t
j
):
def
slice_all
(
unicode
s
,
Py_ssize_t
i
,
Py_ssize_
t
j
):
print
(
s
[:])
def
slice_start_none
(
unicode
s
,
int
i
,
in
t
j
):
def
slice_start_none
(
unicode
s
,
Py_ssize_t
i
,
Py_ssize_
t
j
):
print
(
s
[
i
:
None
])
def
slice_none_end
(
unicode
s
,
int
i
,
in
t
j
):
def
slice_none_end
(
unicode
s
,
Py_ssize_t
i
,
Py_ssize_
t
j
):
print
(
s
[
None
:
i
])
def
slice_none_none
(
unicode
s
,
int
i
,
in
t
j
):
def
slice_none_none
(
unicode
s
,
Py_ssize_t
i
,
Py_ssize_
t
j
):
print
(
s
[
None
:
None
])
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