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
873c5832
Commit
873c5832
authored
Jun 09, 2011
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#10694: zipfile now ignores garbage at the end of a zipfile.
Original fix by 'rep', final patch (with tests) by Xuanji Li.
parent
5446f08c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
10 deletions
+28
-10
Lib/test/test_zipfile.py
Lib/test/test_zipfile.py
+18
-0
Lib/zipfile.py
Lib/zipfile.py
+8
-10
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/test/test_zipfile.py
View file @
873c5832
...
...
@@ -335,6 +335,24 @@ class TestsWithSourceFile(unittest.TestCase):
with
zipfile
.
ZipFile
(
f
,
"r"
)
as
zipfp
:
self
.
assertEqual
(
zipfp
.
namelist
(),
[
TESTFN
])
def
test_ignores_newline_at_end
(
self
):
with
zipfile
.
ZipFile
(
TESTFN2
,
"w"
,
zipfile
.
ZIP_STORED
)
as
zipfp
:
zipfp
.
write
(
TESTFN
,
TESTFN
)
with
open
(
TESTFN2
,
'a'
)
as
f
:
f
.
write
(
"
\
r
\
n
\
00
\
00
\
00
"
)
with
zipfile
.
ZipFile
(
TESTFN2
,
"r"
)
as
zipfp
:
self
.
assertIsInstance
(
zipfp
,
zipfile
.
ZipFile
)
def
test_ignores_stuff_appended_past_comments
(
self
):
with
zipfile
.
ZipFile
(
TESTFN2
,
"w"
,
zipfile
.
ZIP_STORED
)
as
zipfp
:
zipfp
.
comment
=
b"this is a comment"
zipfp
.
write
(
TESTFN
,
TESTFN
)
with
open
(
TESTFN2
,
'a'
)
as
f
:
f
.
write
(
"abcdef
\
r
\
n
"
)
with
zipfile
.
ZipFile
(
TESTFN2
,
"r"
)
as
zipfp
:
self
.
assertIsInstance
(
zipfp
,
zipfile
.
ZipFile
)
self
.
assertEqual
(
zipfp
.
comment
,
b"this is a comment"
)
def
test_write_default_name
(
self
):
"""Check that calling ZipFile.write without arcname specified
produces the expected result."""
...
...
Lib/zipfile.py
View file @
873c5832
...
...
@@ -236,16 +236,14 @@ def _EndRecData(fpin):
# found the magic number; attempt to unpack and interpret
recData
=
data
[
start
:
start
+
sizeEndCentDir
]
endrec
=
list
(
struct
.
unpack
(
structEndArchive
,
recData
))
comment
=
data
[
start
+
sizeEndCentDir
:]
# check that comment length is correct
if
endrec
[
_ECD_COMMENT_SIZE
]
==
len
(
comment
):
# Append the archive comment and start offset
endrec
.
append
(
comment
)
endrec
.
append
(
maxCommentStart
+
start
)
# Try to read the "Zip64 end of central directory" structure
return
_EndRecData64
(
fpin
,
maxCommentStart
+
start
-
filesize
,
endrec
)
commentSize
=
endrec
[
_ECD_COMMENT_SIZE
]
#as claimed by the zip file
comment
=
data
[
start
+
sizeEndCentDir
:
start
+
sizeEndCentDir
+
commentSize
]
endrec
.
append
(
comment
)
endrec
.
append
(
maxCommentStart
+
start
)
# Try to read the "Zip64 end of central directory" structure
return
_EndRecData64
(
fpin
,
maxCommentStart
+
start
-
filesize
,
endrec
)
# Unable to find a valid end of central directory structure
return
...
...
Misc/NEWS
View file @
873c5832
...
...
@@ -16,6 +16,8 @@ Core and Builtins
Library
-------
- Issue #10694: zipfile now ignores garbage at the end of a zipfile.
- Issue #11583: Speed up os.path.isdir on Windows by using GetFileAttributes
instead of os.stat.
...
...
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