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
db9f3355
Commit
db9f3355
authored
Sep 14, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #27599: Fixed buffer overrun in binascii.b2a_qp() and binascii.a2b_qp().
parent
17e73aec
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
28 deletions
+100
-28
Lib/test/test_binascii.py
Lib/test/test_binascii.py
+92
-23
Misc/NEWS
Misc/NEWS
+1
-0
Modules/binascii.c
Modules/binascii.c
+7
-5
No files found.
Lib/test/test_binascii.py
View file @
db9f3355
...
...
@@ -178,37 +178,106 @@ class BinASCIITest(unittest.TestCase):
self
.
assertEqual
(
binascii
.
unhexlify
(
self
.
type2test
(
t
)),
u
)
def
test_qp
(
self
):
binascii
.
a2b_qp
(
data
=
b""
,
header
=
False
)
# Keyword arguments allowed
type2test
=
self
.
type2test
a2b_qp
=
binascii
.
a2b_qp
b2a_qp
=
binascii
.
b2a_qp
a2b_qp
(
data
=
b""
,
header
=
False
)
# Keyword arguments allowed
# A test for SF bug 534347 (segfaults without the proper fix)
try
:
binascii
.
a2b_qp
(
b""
,
**
{
1
:
1
})
a2b_qp
(
b""
,
**
{
1
:
1
})
except
TypeError
:
pass
else
:
self
.
fail
(
"binascii.a2b_qp(**{1:1}) didn't raise TypeError"
)
self
.
assertEqual
(
binascii
.
a2b_qp
(
b"= "
),
b"= "
)
self
.
assertEqual
(
binascii
.
a2b_qp
(
b"=="
),
b"="
)
self
.
assertEqual
(
binascii
.
a2b_qp
(
b"=AX"
),
b"=AX"
)
self
.
assertRaises
(
TypeError
,
binascii
.
b2a_qp
,
foo
=
"bar"
)
self
.
assertEqual
(
binascii
.
a2b_qp
(
b"=00
\
r
\
n
=00"
),
b"
\
x00
\
r
\
n
\
x00
"
)
self
.
assertEqual
(
binascii
.
b2a_qp
(
b"
\
xff
\
r
\
n
\
xff
\
n
\
xff
"
),
self
.
assertEqual
(
a2b_qp
(
type2test
(
b"="
)),
b""
)
self
.
assertEqual
(
a2b_qp
(
type2test
(
b"= "
)),
b"= "
)
self
.
assertEqual
(
a2b_qp
(
type2test
(
b"=="
)),
b"="
)
self
.
assertEqual
(
a2b_qp
(
type2test
(
b"=
\
n
AB"
)),
b"AB"
)
self
.
assertEqual
(
a2b_qp
(
type2test
(
b"=
\
r
\
n
AB"
)),
b"AB"
)
self
.
assertEqual
(
a2b_qp
(
type2test
(
b"=
\
r
AB"
)),
b""
)
# ?
self
.
assertEqual
(
a2b_qp
(
type2test
(
b"=
\
r
AB
\
n
CD"
)),
b"CD"
)
# ?
self
.
assertEqual
(
a2b_qp
(
type2test
(
b"=AB"
)),
b"
\
xab
"
)
self
.
assertEqual
(
a2b_qp
(
type2test
(
b"=ab"
)),
b"
\
xab
"
)
self
.
assertEqual
(
a2b_qp
(
type2test
(
b"=AX"
)),
b"=AX"
)
self
.
assertEqual
(
a2b_qp
(
type2test
(
b"=XA"
)),
b"=XA"
)
self
.
assertEqual
(
a2b_qp
(
type2test
(
b"=AB"
)[:
-
1
]),
b"=A"
)
self
.
assertEqual
(
a2b_qp
(
type2test
(
b'_'
)),
b'_'
)
self
.
assertEqual
(
a2b_qp
(
type2test
(
b'_'
),
header
=
True
),
b' '
)
self
.
assertRaises
(
TypeError
,
b2a_qp
,
foo
=
"bar"
)
self
.
assertEqual
(
a2b_qp
(
type2test
(
b"=00
\
r
\
n
=00"
)),
b"
\
x00
\
r
\
n
\
x00
"
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b"
\
xff
\
r
\
n
\
xff
\
n
\
xff
"
)),
b"=FF
\
r
\
n
=FF
\
r
\
n
=FF"
)
self
.
assertEqual
(
binascii
.
b2a_qp
(
b"0"
*
75
+
b"
\
xff
\
r
\
n
\
xff
\
r
\
n
\
xff
"
),
self
.
assertEqual
(
b2a_qp
(
type2test
(
b"0"
*
75
+
b"
\
xff
\
r
\
n
\
xff
\
r
\
n
\
xff
"
)),
b"0"
*
75
+
b"=
\
r
\
n
=FF
\
r
\
n
=FF
\
r
\
n
=FF"
)
self
.
assertEqual
(
binascii
.
b2a_qp
(
b'
\
0
\
n
'
),
b'=00
\
n
'
)
self
.
assertEqual
(
binascii
.
b2a_qp
(
b'
\
0
\
n
'
,
quotetabs
=
True
),
b'=00
\
n
'
)
self
.
assertEqual
(
binascii
.
b2a_qp
(
b'foo
\
t
bar
\
t
\
n
'
),
b'foo
\
t
bar=09
\
n
'
)
self
.
assertEqual
(
binascii
.
b2a_qp
(
b'foo
\
t
bar
\
t
\
n
'
,
quotetabs
=
True
),
b'foo=09bar=09
\
n
'
)
self
.
assertEqual
(
binascii
.
b2a_qp
(
b'.'
),
b'=2E'
)
self
.
assertEqual
(
binascii
.
b2a_qp
(
b'.
\
n
'
),
b'=2E
\
n
'
)
self
.
assertEqual
(
binascii
.
b2a_qp
(
b'a.
\
n
'
),
b'a.
\
n
'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'
\
x7f
'
)),
b'=7F'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'='
)),
b'=3D'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'_'
)),
b'_'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'_'
),
header
=
True
),
b'=5F'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x y'
),
header
=
True
),
b'x_y'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x '
),
header
=
True
),
b'x=20'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x y'
),
header
=
True
,
quotetabs
=
True
),
b'x=20y'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x
\
t
y'
),
header
=
True
),
b'x
\
t
y'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b' '
)),
b'=20'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'
\
t
'
)),
b'=09'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b' x'
)),
b' x'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'
\
t
x'
)),
b'
\
t
x'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b' x'
)[:
-
1
]),
b'=20'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'
\
t
x'
)[:
-
1
]),
b'=09'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'
\
0
'
)),
b'=00'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'
\
0
\
n
'
)),
b'=00
\
n
'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'
\
0
\
n
'
),
quotetabs
=
True
),
b'=00
\
n
'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x y
\
t
z'
)),
b'x y
\
t
z'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x y
\
t
z'
),
quotetabs
=
True
),
b'x=20y=09z'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x y
\
t
z'
),
istext
=
False
),
b'x y
\
t
z'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x
\
n
y
\
t
\
n
'
)),
b'x=20
\
n
y=09
\
n
'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x
\
n
y
\
t
\
n
'
),
quotetabs
=
True
),
b'x=20
\
n
y=09
\
n
'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x
\
n
y
\
t
\
n
'
),
istext
=
False
),
b'x =0Ay
\
t
=0A'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x
\
r
y
\
t
\
r
'
)),
b'x
\
r
y
\
t
\
r
'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x
\
r
y
\
t
\
r
'
),
quotetabs
=
True
),
b'x=20
\
r
y=09
\
r
'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x
\
r
y
\
t
\
r
'
),
istext
=
False
),
b'x =0Dy
\
t
=0D'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x
\
r
\
n
y
\
t
\
r
\
n
'
)),
b'x=20
\
r
\
n
y=09
\
r
\
n
'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x
\
r
\
n
y
\
t
\
r
\
n
'
),
quotetabs
=
True
),
b'x=20
\
r
\
n
y=09
\
r
\
n
'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x
\
r
\
n
y
\
t
\
r
\
n
'
),
istext
=
False
),
b'x =0D=0Ay
\
t
=0D=0A'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x
\
r
\
n
'
)[:
-
1
]),
b'x
\
r
'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x
\
t
\
r
\
n
'
)[:
-
1
]),
b'x
\
t
\
r
'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x
\
r
\
n
'
)[:
-
1
],
quotetabs
=
True
),
b'x=20
\
r
'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x
\
t
\
r
\
n
'
)[:
-
1
],
quotetabs
=
True
),
b'x=09
\
r
'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x
\
r
\
n
'
)[:
-
1
],
istext
=
False
),
b'x =0D'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'x
\
t
\
r
\
n
'
)[:
-
1
],
istext
=
False
),
b'x
\
t
=0D'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'.'
)),
b'=2E'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'.
\
n
'
)),
b'=2E
\
n
'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'.
\
r
'
)),
b'=2E
\
r
'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'.
\
0
'
)),
b'=2E=00'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'a.
\
n
'
)),
b'a.
\
n
'
)
self
.
assertEqual
(
b2a_qp
(
type2test
(
b'.a'
)[:
-
1
]),
b'=2E'
)
def
test_empty_string
(
self
):
# A test for SF bug #1022953. Make sure SystemError is not raised.
...
...
Misc/NEWS
View file @
db9f3355
...
...
@@ -71,6 +71,7 @@ Core and Builtins
Library
-------
- Issue #27599: Fixed buffer overrun in binascii.b2a_qp() and binascii.a2b_qp().
- Issue #19003:m email.generator now replaces only \r and/or \n line
endings, per the RFC, instead of all unicode line endings.
...
...
Modules/binascii.c
View file @
db9f3355
...
...
@@ -1290,7 +1290,8 @@ binascii_a2b_qp_impl(PyObject *module, Py_buffer *data, int header)
odata
[
out
++
]
=
'='
;
in
++
;
}
else
if
(((
ascii_data
[
in
]
>=
'A'
&&
ascii_data
[
in
]
<=
'F'
)
||
else
if
((
in
+
1
<
datalen
)
&&
((
ascii_data
[
in
]
>=
'A'
&&
ascii_data
[
in
]
<=
'F'
)
||
(
ascii_data
[
in
]
>=
'a'
&&
ascii_data
[
in
]
<=
'f'
)
||
(
ascii_data
[
in
]
>=
'0'
&&
ascii_data
[
in
]
<=
'9'
))
&&
((
ascii_data
[
in
+
1
]
>=
'A'
&&
ascii_data
[
in
+
1
]
<=
'F'
)
||
...
...
@@ -1388,7 +1389,8 @@ binascii_b2a_qp_impl(PyObject *module, Py_buffer *data, int quotetabs,
(
databuf
[
in
]
==
'='
)
||
(
header
&&
databuf
[
in
]
==
'_'
)
||
((
databuf
[
in
]
==
'.'
)
&&
(
linelen
==
0
)
&&
(
databuf
[
in
+
1
]
==
'\n'
||
databuf
[
in
+
1
]
==
'\r'
||
databuf
[
in
+
1
]
==
0
))
||
(
in
+
1
==
datalen
||
databuf
[
in
+
1
]
==
'\n'
||
databuf
[
in
+
1
]
==
'\r'
||
databuf
[
in
+
1
]
==
0
))
||
(
!
istext
&&
((
databuf
[
in
]
==
'\r'
)
||
(
databuf
[
in
]
==
'\n'
)))
||
((
databuf
[
in
]
==
'\t'
||
databuf
[
in
]
==
' '
)
&&
(
in
+
1
==
datalen
))
||
((
databuf
[
in
]
<
33
)
&&
...
...
@@ -1464,13 +1466,13 @@ binascii_b2a_qp_impl(PyObject *module, Py_buffer *data, int quotetabs,
(
databuf
[
in
]
==
'='
)
||
(
header
&&
databuf
[
in
]
==
'_'
)
||
((
databuf
[
in
]
==
'.'
)
&&
(
linelen
==
0
)
&&
(
databuf
[
in
+
1
]
==
'\n'
||
databuf
[
in
+
1
]
==
'\r'
||
databuf
[
in
+
1
]
==
0
))
||
(
in
+
1
==
datalen
||
databuf
[
in
+
1
]
==
'\n'
||
databuf
[
in
+
1
]
==
'\r'
||
databuf
[
in
+
1
]
==
0
))
||
(
!
istext
&&
((
databuf
[
in
]
==
'\r'
)
||
(
databuf
[
in
]
==
'\n'
)))
||
((
databuf
[
in
]
==
'\t'
||
databuf
[
in
]
==
' '
)
&&
(
in
+
1
==
datalen
))
||
((
databuf
[
in
]
<
33
)
&&
(
databuf
[
in
]
!=
'\r'
)
&&
(
databuf
[
in
]
!=
'\n'
)
&&
(
quotetabs
||
(
!
quotetabs
&&
((
databuf
[
in
]
!=
'\t'
)
&&
(
databuf
[
in
]
!=
' '
))))))
(
quotetabs
||
((
databuf
[
in
]
!=
'\t'
)
&&
(
databuf
[
in
]
!=
' '
)))))
{
if
((
linelen
+
3
)
>=
MAXLINESIZE
)
{
odata
[
out
++
]
=
'='
;
...
...
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