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
9e94972e
Commit
9e94972e
authored
Nov 18, 2012
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#14313: zipfile now raises NotImplementedError when the compression type is unknown.
parent
355637be
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
0 deletions
+42
-0
Lib/test/test_zipfile.py
Lib/test/test_zipfile.py
+11
-0
Lib/zipfile.py
Lib/zipfile.py
+28
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/test_zipfile.py
View file @
9e94972e
...
...
@@ -859,6 +859,17 @@ class OtherTests(unittest.TestCase):
caught."""
self
.
assertRaises
(
RuntimeError
,
zipfile
.
ZipFile
,
TESTFN
,
"w"
,
-
1
)
def
test_unsupported_compression
(
self
):
# data is declared as shrunk, but actually deflated
data
=
(
b'PK
\
x03
\
x04
.
\
x00
\
x00
\
x00
\
x01
\
x00
\
xe4
C
\
xa1
@
\
x00
\
x00
\
x00
'
b'
\
x00
\
x02
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x01
\
x00
\
x00
\
x00
x
\
x03
\
x00
PK
\
x01
'
b'
\
x02
.
\
x03
.
\
x00
\
x00
\
x00
\
x01
\
x00
\
xe4
C
\
xa1
@
\
x00
\
x00
\
x00
\
x00
\
x02
\
x00
\
x00
'
b'
\
x00
\
x00
\
x00
\
x00
\
x00
\
x01
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
'
b'
\
x80
\
x01
\
x00
\
x00
\
x00
\
x00
xPK
\
x05
\
x06
\
x00
\
x00
\
x00
\
x00
\
x01
\
x00
\
x01
\
x00
'
b'/
\
x00
\
x00
\
x00
!
\
x00
\
x00
\
x00
\
x00
\
x00
'
)
with
zipfile
.
ZipFile
(
io
.
BytesIO
(
data
),
'r'
)
as
zipf
:
self
.
assertRaises
(
NotImplementedError
,
zipf
.
open
,
'x'
)
def
test_null_byte_in_filename
(
self
):
"""Check that a filename containing a null byte is properly
terminated."""
...
...
Lib/zipfile.py
View file @
9e94972e
...
...
@@ -461,6 +461,28 @@ class _ZipDecrypter:
self
.
_UpdateKeys
(
c
)
return
c
compressor_names
=
{
0
:
'store'
,
1
:
'shrink'
,
2
:
'reduce'
,
3
:
'reduce'
,
4
:
'reduce'
,
5
:
'reduce'
,
6
:
'implode'
,
7
:
'tokenize'
,
8
:
'deflate'
,
9
:
'deflate64'
,
10
:
'implode'
,
12
:
'bzip2'
,
14
:
'lzma'
,
18
:
'terse'
,
19
:
'lz77'
,
97
:
'wavpack'
,
98
:
'ppmd'
,
}
class
ZipExtFile
(
io
.
BufferedIOBase
):
"""File-like object for reading an archive member.
Is returned by ZipFile.open().
...
...
@@ -487,6 +509,12 @@ class ZipExtFile(io.BufferedIOBase):
if
self
.
_compress_type
==
ZIP_DEFLATED
:
self
.
_decompressor
=
zlib
.
decompressobj
(
-
15
)
elif
self
.
_compress_type
!=
ZIP_STORED
:
descr
=
compressor_names
.
get
(
self
.
_compress_type
)
if
descr
:
raise
NotImplementedError
(
"compression type %d (%s)"
%
(
self
.
_compress_type
,
descr
))
else
:
raise
NotImplementedError
(
"compression type %d"
%
(
self
.
_compress_type
,))
self
.
_unconsumed
=
''
self
.
_readbuffer
=
''
...
...
Misc/NEWS
View file @
9e94972e
...
...
@@ -148,6 +148,9 @@ Core and Builtins
Library
-------
-
Issue
#
14313
:
zipfile
now
raises
NotImplementedError
when
the
compression
type
is
unknown
.
-
Issue
#
16408
:
Fix
file
descriptors
not
being
closed
in
error
conditions
in
the
zipfile
module
.
Patch
by
Serhiy
Storchaka
.
...
...
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