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
29034baf
Commit
29034baf
authored
Sep 18, 2018
by
Serhiy Storchaka
Committed by
GitHub
Sep 18, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.7] bpo-34341: Fix appending to ZIP archives with the ZIP64 extension. (GH-8683). (GH-9400)
(cherry picked from commit
9bdb7be4
)
parent
18b20bad
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
0 deletions
+38
-0
Lib/test/test_zipfile.py
Lib/test/test_zipfile.py
+14
-0
Lib/zipfile.py
Lib/zipfile.py
+22
-0
Misc/NEWS.d/next/Library/2018-08-06-11-01-18.bpo-34341.E0b9p2.rst
...S.d/next/Library/2018-08-06-11-01-18.bpo-34341.E0b9p2.rst
+2
-0
No files found.
Lib/test/test_zipfile.py
View file @
29034baf
...
@@ -812,6 +812,20 @@ class TestZip64InSmallFiles(unittest.TestCase):
...
@@ -812,6 +812,20 @@ class TestZip64InSmallFiles(unittest.TestCase):
self
.
assertEqual
(
content
,
"%d"
%
(
i
**
3
%
57
))
self
.
assertEqual
(
content
,
"%d"
%
(
i
**
3
%
57
))
zipf2
.
close
()
zipf2
.
close
()
def
test_append
(
self
):
# Test that appending to the Zip64 archive doesn't change
# extra fields of existing entries.
with
zipfile
.
ZipFile
(
TESTFN2
,
"w"
,
allowZip64
=
True
)
as
zipfp
:
zipfp
.
writestr
(
"strfile"
,
self
.
data
)
with
zipfile
.
ZipFile
(
TESTFN2
,
"r"
,
allowZip64
=
True
)
as
zipfp
:
zinfo
=
zipfp
.
getinfo
(
"strfile"
)
extra
=
zinfo
.
extra
with
zipfile
.
ZipFile
(
TESTFN2
,
"a"
,
allowZip64
=
True
)
as
zipfp
:
zipfp
.
writestr
(
"strfile2"
,
self
.
data
)
with
zipfile
.
ZipFile
(
TESTFN2
,
"r"
,
allowZip64
=
True
)
as
zipfp
:
zinfo
=
zipfp
.
getinfo
(
"strfile"
)
self
.
assertEqual
(
zinfo
.
extra
,
extra
)
def
tearDown
(
self
):
def
tearDown
(
self
):
zipfile
.
ZIP64_LIMIT
=
self
.
_limit
zipfile
.
ZIP64_LIMIT
=
self
.
_limit
zipfile
.
ZIP_FILECOUNT_LIMIT
=
self
.
_filecount_limit
zipfile
.
ZIP_FILECOUNT_LIMIT
=
self
.
_filecount_limit
...
...
Lib/zipfile.py
View file @
29034baf
...
@@ -131,6 +131,27 @@ _CD64_NUMBER_ENTRIES_TOTAL = 7
...
@@ -131,6 +131,27 @@ _CD64_NUMBER_ENTRIES_TOTAL = 7
_CD64_DIRECTORY_SIZE
=
8
_CD64_DIRECTORY_SIZE
=
8
_CD64_OFFSET_START_CENTDIR
=
9
_CD64_OFFSET_START_CENTDIR
=
9
_EXTRA_FIELD_STRUCT
=
struct
.
Struct
(
'<HH'
)
def
_strip_extra
(
extra
,
xids
):
# Remove Extra Fields with specified IDs.
unpack
=
_EXTRA_FIELD_STRUCT
.
unpack
modified
=
False
buffer
=
[]
start
=
i
=
0
while
i
+
4
<=
len
(
extra
):
xid
,
xlen
=
unpack
(
extra
[
i
:
i
+
4
])
j
=
i
+
4
+
xlen
if
xid
in
xids
:
if
i
!=
start
:
buffer
.
append
(
extra
[
start
:
i
])
start
=
j
modified
=
True
i
=
j
if
not
modified
:
return
extra
return
b''
.
join
(
buffer
)
def
_check_zipfile
(
fp
):
def
_check_zipfile
(
fp
):
try
:
try
:
if
_EndRecData
(
fp
):
if
_EndRecData
(
fp
):
...
@@ -1293,6 +1314,7 @@ class ZipFile(object):
...
@@ -1293,6 +1314,7 @@ class ZipFile(object):
extra_data
=
zinfo
.
extra
extra_data
=
zinfo
.
extra
if
extra
:
if
extra
:
# Append a ZIP64 field to the extra's
# Append a ZIP64 field to the extra's
extra_data
=
_strip_extra
(
extra_data
,
(
1
,))
extra_data
=
struct
.
pack
(
extra_data
=
struct
.
pack
(
'<HH'
+
'Q'
*
len
(
extra
),
'<HH'
+
'Q'
*
len
(
extra
),
1
,
8
*
len
(
extra
),
*
extra
)
+
extra_data
1
,
8
*
len
(
extra
),
*
extra
)
+
extra_data
...
...
Misc/NEWS.d/next/Library/2018-08-06-11-01-18.bpo-34341.E0b9p2.rst
0 → 100644
View file @
29034baf
Appending to the ZIP archive with the ZIP64 extension no longer grows the
size of extra fields of existing entries.
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