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
23cf403c
Commit
23cf403c
authored
Mar 30, 2014
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix expandtabs overflow detection to be consistent and not rely on signed overflow
parent
cf25c5ca
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
19 deletions
+19
-19
Objects/stringlib/transmogrify.h
Objects/stringlib/transmogrify.h
+19
-19
No files found.
Objects/stringlib/transmogrify.h
View file @
23cf403c
...
...
@@ -15,7 +15,7 @@ stringlib_expandtabs(PyObject *self, PyObject *args)
{
const
char
*
e
,
*
p
;
char
*
q
;
size_t
i
,
j
;
Py_s
size_t
i
,
j
;
PyObject
*
u
;
int
tabsize
=
8
;
...
...
@@ -25,35 +25,31 @@ stringlib_expandtabs(PyObject *self, PyObject *args)
/* First pass: determine size of output string */
i
=
j
=
0
;
e
=
STRINGLIB_STR
(
self
)
+
STRINGLIB_LEN
(
self
);
for
(
p
=
STRINGLIB_STR
(
self
);
p
<
e
;
p
++
)
for
(
p
=
STRINGLIB_STR
(
self
);
p
<
e
;
p
++
)
{
if
(
*
p
==
'\t'
)
{
if
(
tabsize
>
0
)
{
j
+=
tabsize
-
(
j
%
tabsize
);
if
(
j
>
PY_SSIZE_T_MAX
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"result is too long"
);
return
NULL
;
}
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'
||
*
p
==
'\r'
)
{
if
(
i
>
PY_SSIZE_T_MAX
-
j
)
goto
overflow
;
i
+=
j
;
j
=
0
;
if
(
i
>
PY_SSIZE_T_MAX
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"result is too long"
);
return
NULL
;
}
}
}
if
((
i
+
j
)
>
PY_SSIZE_T_MAX
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"result is too long"
);
return
NULL
;
}
if
(
i
>
PY_SSIZE_T_MAX
-
j
)
goto
overflow
;
/* Second pass: create output string and fill it */
u
=
STRINGLIB_NEW
(
NULL
,
i
+
j
);
if
(
!
u
)
...
...
@@ -62,7 +58,7 @@ stringlib_expandtabs(PyObject *self, PyObject *args)
j
=
0
;
q
=
STRINGLIB_STR
(
u
);
for
(
p
=
STRINGLIB_STR
(
self
);
p
<
e
;
p
++
)
for
(
p
=
STRINGLIB_STR
(
self
);
p
<
e
;
p
++
)
{
if
(
*
p
==
'\t'
)
{
if
(
tabsize
>
0
)
{
i
=
tabsize
-
(
j
%
tabsize
);
...
...
@@ -77,8 +73,12 @@ stringlib_expandtabs(PyObject *self, PyObject *args)
if
(
*
p
==
'\n'
||
*
p
==
'\r'
)
j
=
0
;
}
}
return
u
;
overflow:
PyErr_SetString
(
PyExc_OverflowError
,
"result too long"
);
return
NULL
;
}
Py_LOCAL_INLINE
(
PyObject
*
)
...
...
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