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
3b14cd85
Commit
3b14cd85
authored
Oct 21, 2012
by
Nadeem Vawda
Browse files
Options
Browse Files
Download
Plain Diff
Merge #14398: Fix size truncation and overflow bugs in bz2 module.
parents
838ba4ac
76eb6ea2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
9 deletions
+26
-9
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_bz2module.c
Modules/_bz2module.c
+24
-9
No files found.
Misc/NEWS
View file @
3b14cd85
...
...
@@ -59,6 +59,8 @@ Core and Builtins
Library
-------
-
Issue
#
14398
:
Fix
size
truncation
and
overflow
bugs
in
the
bz2
module
.
-
Issue
#
12692
:
Fix
resource
leak
in
urllib
.
request
when
talking
to
an
HTTP
server
that
does
not
include
a
"Connection: close"
header
in
its
responses
.
...
...
Modules/_bz2module.c
View file @
3b14cd85
...
...
@@ -123,7 +123,14 @@ grow_buffer(PyObject **buf)
giving us amortized linear-time behavior. Use a less-than-double
growth factor to avoid excessive allocation. */
size_t
size
=
PyBytes_GET_SIZE
(
*
buf
);
return
_PyBytes_Resize
(
buf
,
size
+
(
size
>>
3
)
+
6
);
size_t
new_size
=
size
+
(
size
>>
3
)
+
6
;
if
(
new_size
>
size
)
{
return
_PyBytes_Resize
(
buf
,
new_size
);
}
else
{
/* overflow */
PyErr_SetString
(
PyExc_OverflowError
,
"Unable to allocate buffer - output too large"
);
return
-
1
;
}
}
...
...
@@ -169,10 +176,14 @@ compress(BZ2Compressor *c, char *data, size_t len, int action)
break
;
if
(
c
->
bzs
.
avail_out
==
0
)
{
if
(
grow_buffer
(
&
result
)
<
0
)
goto
error
;
c
->
bzs
.
next_out
=
PyBytes_AS_STRING
(
result
)
+
data_size
;
c
->
bzs
.
avail_out
=
PyBytes_GET_SIZE
(
result
)
-
data_size
;
size_t
buffer_left
=
PyBytes_GET_SIZE
(
result
)
-
data_size
;
if
(
buffer_left
==
0
)
{
if
(
grow_buffer
(
&
result
)
<
0
)
goto
error
;
c
->
bzs
.
next_out
=
PyBytes_AS_STRING
(
result
)
+
data_size
;
buffer_left
=
PyBytes_GET_SIZE
(
result
)
-
data_size
;
}
c
->
bzs
.
avail_out
=
MIN
(
buffer_left
,
UINT_MAX
);
}
}
if
(
data_size
!=
PyBytes_GET_SIZE
(
result
))
...
...
@@ -390,10 +401,14 @@ decompress(BZ2Decompressor *d, char *data, size_t len)
len
-=
d
->
bzs
.
avail_in
;
}
if
(
d
->
bzs
.
avail_out
==
0
)
{
if
(
grow_buffer
(
&
result
)
<
0
)
goto
error
;
d
->
bzs
.
next_out
=
PyBytes_AS_STRING
(
result
)
+
data_size
;
d
->
bzs
.
avail_out
=
PyBytes_GET_SIZE
(
result
)
-
data_size
;
size_t
buffer_left
=
PyBytes_GET_SIZE
(
result
)
-
data_size
;
if
(
buffer_left
==
0
)
{
if
(
grow_buffer
(
&
result
)
<
0
)
goto
error
;
d
->
bzs
.
next_out
=
PyBytes_AS_STRING
(
result
)
+
data_size
;
buffer_left
=
PyBytes_GET_SIZE
(
result
)
-
data_size
;
}
d
->
bzs
.
avail_out
=
MIN
(
buffer_left
,
UINT_MAX
);
}
}
if
(
data_size
!=
PyBytes_GET_SIZE
(
result
))
...
...
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