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
4013c179
Commit
4013c179
authored
Dec 03, 2018
by
Serhiy Storchaka
Committed by
GitHub
Dec 03, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-35372: Fix the code page decoder for input > 2 GiB. (GH-10848)
parent
062cbb67
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
5 deletions
+24
-5
Lib/test/test_codecs.py
Lib/test/test_codecs.py
+18
-0
Misc/NEWS.d/next/Core and Builtins/2018-12-01-19-20-53.bpo-35372.RwVJjZ.rst
...ore and Builtins/2018-12-01-19-20-53.bpo-35372.RwVJjZ.rst
+2
-0
Objects/unicodeobject.c
Objects/unicodeobject.c
+4
-5
No files found.
Lib/test/test_codecs.py
View file @
4013c179
...
...
@@ -3190,6 +3190,24 @@ class CodePageTest(unittest.TestCase):
codec = codecs.lookup('cp123')
self.assertEqual(codec.name, 'mbcs')
@support.bigmemtest(size=2**31, memuse=7, dry_run=False)
def test_large_input(self):
# Test input longer than INT_MAX.
# Input should contain undecodable bytes before and after
# the INT_MAX limit.
encoded = (b'01234567' * (2**28-1) +
b'
\
x85
\
x86
\
xea
\
xeb
\
xec
\
xef
\
xfc
\
xfd
\
xfe
\
xff
')
self.assertEqual(len(encoded), 2**31+2)
decoded = codecs.code_page_decode(932, encoded, 'surrogateescape', True)
self.assertEqual(decoded[1], len(encoded))
del encoded
self.assertEqual(len(decoded[0]), decoded[1])
self.assertEqual(decoded[0][:10], '0123456701')
self.assertEqual(decoded[0][-20:],
'6701234567'
'
\
udc85
\
udc86
\
udcea
\
udceb
\
udcec
'
'
\
udcef
\
udcfc
\
udcfd
\
udcfe
\
udcff
')
class ASCIITest(unittest.TestCase):
def test_encode(self):
...
...
Misc/NEWS.d/next/Core and Builtins/2018-12-01-19-20-53.bpo-35372.RwVJjZ.rst
0 → 100644
View file @
4013c179
Fixed the code page decoder for input longer than 2 GiB containing
undecodable bytes.
Objects/unicodeobject.c
View file @
4013c179
...
...
@@ -7211,7 +7211,7 @@ decode_code_page_errors(UINT code_page,
"in the target code page."
;
/* each step cannot decode more than 1 character, but a character can be
represented as a surrogate pair */
wchar_t
buffer
[
2
],
*
startout
,
*
out
;
wchar_t
buffer
[
2
],
*
out
;
int
insize
;
Py_ssize_t
outsize
;
PyObject
*
errorHandler
=
NULL
;
...
...
@@ -7248,7 +7248,7 @@ decode_code_page_errors(UINT code_page,
*
v
=
(
PyObject
*
)
_PyUnicode_New
(
size
*
Py_ARRAY_LENGTH
(
buffer
));
if
(
*
v
==
NULL
)
goto
error
;
start
out
=
PyUnicode_AS_UNICODE
(
*
v
);
out
=
PyUnicode_AS_UNICODE
(
*
v
);
}
else
{
/* Extend unicode object */
...
...
@@ -7259,11 +7259,10 @@ decode_code_page_errors(UINT code_page,
}
if
(
unicode_resize
(
v
,
n
+
size
*
Py_ARRAY_LENGTH
(
buffer
))
<
0
)
goto
error
;
start
out
=
PyUnicode_AS_UNICODE
(
*
v
)
+
n
;
out
=
PyUnicode_AS_UNICODE
(
*
v
)
+
n
;
}
/* Decode the byte string character per character */
out
=
startout
;
while
(
in
<
endin
)
{
/* Decode a character */
...
...
@@ -7318,7 +7317,7 @@ decode_code_page_errors(UINT code_page,
*
out
=
0
;
/* Extend unicode object */
outsize
=
out
-
startout
;
outsize
=
out
-
PyUnicode_AS_UNICODE
(
*
v
)
;
assert
(
outsize
<=
PyUnicode_WSTR_LENGTH
(
*
v
));
if
(
unicode_resize
(
v
,
outsize
)
<
0
)
goto
error
;
...
...
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