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
57cb81d1
Commit
57cb81d1
authored
Jan 02, 2013
by
Nadeem Vawda
Browse files
Options
Browse Files
Download
Plain Diff
Issue #16828: Fix error incorrectly raised by bz2.compress('').
Initial patch by Martin Packman.
parents
407c2ac4
638fb9bb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
16 deletions
+37
-16
Lib/test/test_bz2.py
Lib/test/test_bz2.py
+15
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_bz2module.c
Modules/_bz2module.c
+18
-16
No files found.
Lib/test/test_bz2.py
View file @
57cb81d1
...
@@ -47,6 +47,7 @@ class BaseTest(unittest.TestCase):
...
@@ -47,6 +47,7 @@ class BaseTest(unittest.TestCase):
]
]
TEXT
=
b''
.
join
(
TEXT_LINES
)
TEXT
=
b''
.
join
(
TEXT_LINES
)
DATA
=
b'BZh91AY&SY.
\
xc8
N
\
x18
\
x00
\
x01
>_
\
x80
\
x00
\
x10
@
\
x02
\
xff
\
xf0
\
x01
\
x07
n
\
x00
?
\
xe7
\
xff
\
xe0
0
\
x01
\
x99
\
xaa
\
x00
\
xc0
\
x03
F
\
x86
\
x8c
#&
\
x83
F
\
x9a
\
x03
\
x06
\
xa6
\
xd0
\
xa6
\
x93
M
\
x0f
Q
\
xa7
\
xa8
\
x06
\
x80
4hh
\
x12
$
\
x11
\
xa4
i4
\
xf1
4S
\
x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
\
xc9
\
x14
\
xe1
B@
\
xbb
!8`'
EMPTY_DATA
=
b'BZh9
\
x17
rE8P
\
x90
\
x00
\
x00
\
x00
\
x00
'
def
setUp
(
self
):
def
setUp
(
self
):
self
.
filename
=
TESTFN
self
.
filename
=
TESTFN
...
@@ -584,6 +585,12 @@ class BZ2CompressorTest(BaseTest):
...
@@ -584,6 +585,12 @@ class BZ2CompressorTest(BaseTest):
data
+=
bz2c
.
flush
()
data
+=
bz2c
.
flush
()
self
.
assertEqual
(
self
.
decompress
(
data
),
self
.
TEXT
)
self
.
assertEqual
(
self
.
decompress
(
data
),
self
.
TEXT
)
def
testCompressEmptyString
(
self
):
bz2c
=
BZ2Compressor
()
data
=
bz2c
.
compress
(
b''
)
data
+=
bz2c
.
flush
()
self
.
assertEqual
(
data
,
self
.
EMPTY_DATA
)
def
testCompressChunks10
(
self
):
def
testCompressChunks10
(
self
):
bz2c
=
BZ2Compressor
()
bz2c
=
BZ2Compressor
()
n
=
0
n
=
0
...
@@ -671,6 +678,10 @@ class CompressDecompressTest(BaseTest):
...
@@ -671,6 +678,10 @@ class CompressDecompressTest(BaseTest):
data
=
bz2
.
compress
(
self
.
TEXT
)
data
=
bz2
.
compress
(
self
.
TEXT
)
self
.
assertEqual
(
self
.
decompress
(
data
),
self
.
TEXT
)
self
.
assertEqual
(
self
.
decompress
(
data
),
self
.
TEXT
)
def
testCompressEmptyString
(
self
):
text
=
bz2
.
compress
(
b''
)
self
.
assertEqual
(
text
,
self
.
EMPTY_DATA
)
def
testDecompress
(
self
):
def
testDecompress
(
self
):
text
=
bz2
.
decompress
(
self
.
DATA
)
text
=
bz2
.
decompress
(
self
.
DATA
)
self
.
assertEqual
(
text
,
self
.
TEXT
)
self
.
assertEqual
(
text
,
self
.
TEXT
)
...
@@ -679,6 +690,10 @@ class CompressDecompressTest(BaseTest):
...
@@ -679,6 +690,10 @@ class CompressDecompressTest(BaseTest):
text
=
bz2
.
decompress
(
b""
)
text
=
bz2
.
decompress
(
b""
)
self
.
assertEqual
(
text
,
b""
)
self
.
assertEqual
(
text
,
b""
)
def
testDecompressToEmptyString
(
self
):
text
=
bz2
.
decompress
(
self
.
EMPTY_DATA
)
self
.
assertEqual
(
text
,
b''
)
def
testDecompressIncomplete
(
self
):
def
testDecompressIncomplete
(
self
):
self
.
assertRaises
(
ValueError
,
bz2
.
decompress
,
self
.
DATA
[:
-
10
])
self
.
assertRaises
(
ValueError
,
bz2
.
decompress
,
self
.
DATA
[:
-
10
])
...
...
Misc/ACKS
View file @
57cb81d1
...
@@ -884,6 +884,7 @@ Michael Otteneder
...
@@ -884,6 +884,7 @@ Michael Otteneder
R. M. Oudkerk
R. M. Oudkerk
Russel Owen
Russel Owen
Joonas Paalasmaa
Joonas Paalasmaa
Martin Packman
Shriphani Palakodety
Shriphani Palakodety
Ondrej Palkovsky
Ondrej Palkovsky
Mike Pall
Mike Pall
...
...
Misc/NEWS
View file @
57cb81d1
...
@@ -123,6 +123,9 @@ Core and Builtins
...
@@ -123,6 +123,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #16828: Fix error incorrectly raised by bz2.compress(''). Initial patch
by Martin Packman.
- Issue #16541: tk_setPalette() now works with keyword arguments.
- Issue #16541: tk_setPalette() now works with keyword arguments.
- Issue #16820: In configparser, `parser.popitem()` no longer raises ValueError.
- Issue #16820: In configparser, `parser.popitem()` no longer raises ValueError.
...
...
Modules/_bz2module.c
View file @
57cb81d1
...
@@ -145,34 +145,24 @@ compress(BZ2Compressor *c, char *data, size_t len, int action)
...
@@ -145,34 +145,24 @@ compress(BZ2Compressor *c, char *data, size_t len, int action)
result
=
PyBytes_FromStringAndSize
(
NULL
,
SMALLCHUNK
);
result
=
PyBytes_FromStringAndSize
(
NULL
,
SMALLCHUNK
);
if
(
result
==
NULL
)
if
(
result
==
NULL
)
return
NULL
;
return
NULL
;
c
->
bzs
.
next_in
=
data
;
c
->
bzs
.
next_in
=
data
;
/* On a 64-bit system, len might not fit in avail_in (an unsigned int).
c
->
bzs
.
avail_in
=
0
;
Do compression in chunks of no more than UINT_MAX bytes each. */
c
->
bzs
.
avail_in
=
MIN
(
len
,
UINT_MAX
);
len
-=
c
->
bzs
.
avail_in
;
c
->
bzs
.
next_out
=
PyBytes_AS_STRING
(
result
);
c
->
bzs
.
next_out
=
PyBytes_AS_STRING
(
result
);
c
->
bzs
.
avail_out
=
PyBytes_GET_SIZE
(
result
);
c
->
bzs
.
avail_out
=
PyBytes_GET_SIZE
(
result
);
for
(;;)
{
for
(;;)
{
char
*
this_out
;
char
*
this_out
;
int
bzerror
;
int
bzerror
;
Py_BEGIN_ALLOW_THREADS
/* On a 64-bit system, len might not fit in avail_in (an unsigned int).
this_out
=
c
->
bzs
.
next_out
;
Do compression in chunks of no more than UINT_MAX bytes each. */
bzerror
=
BZ2_bzCompress
(
&
c
->
bzs
,
action
);
data_size
+=
c
->
bzs
.
next_out
-
this_out
;
Py_END_ALLOW_THREADS
if
(
catch_bz2_error
(
bzerror
))
goto
error
;
if
(
c
->
bzs
.
avail_in
==
0
&&
len
>
0
)
{
if
(
c
->
bzs
.
avail_in
==
0
&&
len
>
0
)
{
c
->
bzs
.
avail_in
=
MIN
(
len
,
UINT_MAX
);
c
->
bzs
.
avail_in
=
MIN
(
len
,
UINT_MAX
);
len
-=
c
->
bzs
.
avail_in
;
len
-=
c
->
bzs
.
avail_in
;
}
}
/* In regular compression mode, stop when input data is exhausted.
/* In regular compression mode, stop when input data is exhausted. */
In flushing mode, stop when all buffered data has been flushed. */
if
(
action
==
BZ_RUN
&&
c
->
bzs
.
avail_in
==
0
)
if
((
action
==
BZ_RUN
&&
c
->
bzs
.
avail_in
==
0
)
||
(
action
==
BZ_FINISH
&&
bzerror
==
BZ_STREAM_END
))
break
;
break
;
if
(
c
->
bzs
.
avail_out
==
0
)
{
if
(
c
->
bzs
.
avail_out
==
0
)
{
...
@@ -185,6 +175,18 @@ compress(BZ2Compressor *c, char *data, size_t len, int action)
...
@@ -185,6 +175,18 @@ compress(BZ2Compressor *c, char *data, size_t len, int action)
}
}
c
->
bzs
.
avail_out
=
MIN
(
buffer_left
,
UINT_MAX
);
c
->
bzs
.
avail_out
=
MIN
(
buffer_left
,
UINT_MAX
);
}
}
Py_BEGIN_ALLOW_THREADS
this_out
=
c
->
bzs
.
next_out
;
bzerror
=
BZ2_bzCompress
(
&
c
->
bzs
,
action
);
data_size
+=
c
->
bzs
.
next_out
-
this_out
;
Py_END_ALLOW_THREADS
if
(
catch_bz2_error
(
bzerror
))
goto
error
;
/* In flushing mode, stop when all buffered data has been flushed. */
if
(
action
==
BZ_FINISH
&&
bzerror
==
BZ_STREAM_END
)
break
;
}
}
if
(
data_size
!=
PyBytes_GET_SIZE
(
result
))
if
(
data_size
!=
PyBytes_GET_SIZE
(
result
))
if
(
_PyBytes_Resize
(
&
result
,
data_size
)
<
0
)
if
(
_PyBytes_Resize
(
&
result
,
data_size
)
<
0
)
...
...
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