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
182d7cd5
Commit
182d7cd5
authored
Jan 15, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #9720: zipfile now writes correct local headers for files larger than 4 GiB.
parent
03530b98
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
15 deletions
+35
-15
Lib/zipfile.py
Lib/zipfile.py
+32
-15
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/zipfile.py
View file @
182d7cd5
...
@@ -326,7 +326,7 @@ class ZipInfo (object):
...
@@ -326,7 +326,7 @@ class ZipInfo (object):
# compress_size Size of the compressed file
# compress_size Size of the compressed file
# file_size Size of the uncompressed file
# file_size Size of the uncompressed file
def
FileHeader
(
self
):
def
FileHeader
(
self
,
zip64
=
None
):
"""Return the per-file header as a string."""
"""Return the per-file header as a string."""
dt
=
self
.
date_time
dt
=
self
.
date_time
dosdate
=
(
dt
[
0
]
-
1980
)
<<
9
|
dt
[
1
]
<<
5
|
dt
[
2
]
dosdate
=
(
dt
[
0
]
-
1980
)
<<
9
|
dt
[
1
]
<<
5
|
dt
[
2
]
...
@@ -341,12 +341,17 @@ class ZipInfo (object):
...
@@ -341,12 +341,17 @@ class ZipInfo (object):
extra
=
self
.
extra
extra
=
self
.
extra
if
file_size
>
ZIP64_LIMIT
or
compress_size
>
ZIP64_LIMIT
:
if
zip64
is
None
:
# File is larger than what fits into a 4 byte integer,
zip64
=
file_size
>
ZIP64_LIMIT
or
compress_size
>
ZIP64_LIMIT
# fall back to the ZIP64 extension
if
zip64
:
fmt
=
'<HHQQ'
fmt
=
'<HHQQ'
extra
=
extra
+
struct
.
pack
(
fmt
,
extra
=
extra
+
struct
.
pack
(
fmt
,
1
,
struct
.
calcsize
(
fmt
)
-
4
,
file_size
,
compress_size
)
1
,
struct
.
calcsize
(
fmt
)
-
4
,
file_size
,
compress_size
)
if
file_size
>
ZIP64_LIMIT
or
compress_size
>
ZIP64_LIMIT
:
if
not
zip64
:
raise
LargeZipFile
(
"Filesize would require ZIP64 extensions"
)
# File is larger than what fits into a 4 byte integer,
# fall back to the ZIP64 extension
file_size
=
0xffffffff
file_size
=
0xffffffff
compress_size
=
0xffffffff
compress_size
=
0xffffffff
self
.
extract_version
=
max
(
45
,
self
.
extract_version
)
self
.
extract_version
=
max
(
45
,
self
.
extract_version
)
...
@@ -1135,20 +1140,23 @@ class ZipFile:
...
@@ -1135,20 +1140,23 @@ class ZipFile:
zinfo
.
CRC
=
0
zinfo
.
CRC
=
0
self
.
filelist
.
append
(
zinfo
)
self
.
filelist
.
append
(
zinfo
)
self
.
NameToInfo
[
zinfo
.
filename
]
=
zinfo
self
.
NameToInfo
[
zinfo
.
filename
]
=
zinfo
self
.
fp
.
write
(
zinfo
.
FileHeader
())
self
.
fp
.
write
(
zinfo
.
FileHeader
(
False
))
return
return
with
open
(
filename
,
"rb"
)
as
fp
:
with
open
(
filename
,
"rb"
)
as
fp
:
# Must overwrite CRC and sizes with correct data later
# Must overwrite CRC and sizes with correct data later
zinfo
.
CRC
=
CRC
=
0
zinfo
.
CRC
=
CRC
=
0
zinfo
.
compress_size
=
compress_size
=
0
zinfo
.
compress_size
=
compress_size
=
0
zinfo
.
file_size
=
file_size
=
0
# Compressed size can be larger than uncompressed size
self
.
fp
.
write
(
zinfo
.
FileHeader
())
zip64
=
self
.
_allowZip64
and
\
zinfo
.
file_size
*
1.05
>
ZIP64_LIMIT
self
.
fp
.
write
(
zinfo
.
FileHeader
(
zip64
))
if
zinfo
.
compress_type
==
ZIP_DEFLATED
:
if
zinfo
.
compress_type
==
ZIP_DEFLATED
:
cmpr
=
zlib
.
compressobj
(
zlib
.
Z_DEFAULT_COMPRESSION
,
cmpr
=
zlib
.
compressobj
(
zlib
.
Z_DEFAULT_COMPRESSION
,
zlib
.
DEFLATED
,
-
15
)
zlib
.
DEFLATED
,
-
15
)
else
:
else
:
cmpr
=
None
cmpr
=
None
file_size
=
0
while
1
:
while
1
:
buf
=
fp
.
read
(
1024
*
8
)
buf
=
fp
.
read
(
1024
*
8
)
if
not
buf
:
if
not
buf
:
...
@@ -1168,11 +1176,16 @@ class ZipFile:
...
@@ -1168,11 +1176,16 @@ class ZipFile:
zinfo
.
compress_size
=
file_size
zinfo
.
compress_size
=
file_size
zinfo
.
CRC
=
CRC
zinfo
.
CRC
=
CRC
zinfo
.
file_size
=
file_size
zinfo
.
file_size
=
file_size
# Seek backwards and write CRC and file sizes
if
not
zip64
and
self
.
_allowZip64
:
if
file_size
>
ZIP64_LIMIT
:
raise
RuntimeError
(
'File size has increased during compressing'
)
if
compress_size
>
ZIP64_LIMIT
:
raise
RuntimeError
(
'Compressed size larger than uncompressed size'
)
# Seek backwards and write file header (which will now include
# correct CRC and file sizes)
position
=
self
.
fp
.
tell
()
# Preserve current position in file
position
=
self
.
fp
.
tell
()
# Preserve current position in file
self
.
fp
.
seek
(
zinfo
.
header_offset
+
14
,
0
)
self
.
fp
.
seek
(
zinfo
.
header_offset
,
0
)
self
.
fp
.
write
(
struct
.
pack
(
"<LLL"
,
zinfo
.
CRC
,
zinfo
.
compress_size
,
self
.
fp
.
write
(
zinfo
.
FileHeader
(
zip64
))
zinfo
.
file_size
))
self
.
fp
.
seek
(
position
,
0
)
self
.
fp
.
seek
(
position
,
0
)
self
.
filelist
.
append
(
zinfo
)
self
.
filelist
.
append
(
zinfo
)
self
.
NameToInfo
[
zinfo
.
filename
]
=
zinfo
self
.
NameToInfo
[
zinfo
.
filename
]
=
zinfo
...
@@ -1212,14 +1225,18 @@ class ZipFile:
...
@@ -1212,14 +1225,18 @@ class ZipFile:
zinfo
.
compress_size
=
len
(
data
)
# Compressed size
zinfo
.
compress_size
=
len
(
data
)
# Compressed size
else
:
else
:
zinfo
.
compress_size
=
zinfo
.
file_size
zinfo
.
compress_size
=
zinfo
.
file_size
zinfo
.
header_offset
=
self
.
fp
.
tell
()
# Start of header data
zip64
=
zinfo
.
file_size
>
ZIP64_LIMIT
or
\
self
.
fp
.
write
(
zinfo
.
FileHeader
())
zinfo
.
compress_size
>
ZIP64_LIMIT
if
zip64
and
not
self
.
_allowZip64
:
raise
LargeZipFile
(
"Filesize would require ZIP64 extensions"
)
self
.
fp
.
write
(
zinfo
.
FileHeader
(
zip64
))
self
.
fp
.
write
(
data
)
self
.
fp
.
write
(
data
)
self
.
fp
.
flush
()
if
zinfo
.
flag_bits
&
0x08
:
if
zinfo
.
flag_bits
&
0x08
:
# Write CRC and file sizes after the file data
# Write CRC and file sizes after the file data
self
.
fp
.
write
(
struct
.
pack
(
"<LLL"
,
zinfo
.
CRC
,
zinfo
.
compress_size
,
fmt
=
'<LQQ'
if
zip64
else
'<LLL'
self
.
fp
.
write
(
struct
.
pack
(
fmt
,
zinfo
.
CRC
,
zinfo
.
compress_size
,
zinfo
.
file_size
))
zinfo
.
file_size
))
self
.
fp
.
flush
()
self
.
filelist
.
append
(
zinfo
)
self
.
filelist
.
append
(
zinfo
)
self
.
NameToInfo
[
zinfo
.
filename
]
=
zinfo
self
.
NameToInfo
[
zinfo
.
filename
]
=
zinfo
...
...
Misc/NEWS
View file @
182d7cd5
...
@@ -199,6 +199,9 @@ Core and Builtins
...
@@ -199,6 +199,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #9720: zipfile now writes correct local headers for files larger than
4 GiB.
- Issue #16829: IDLE printing no longer fails if there are spaces or other
- Issue #16829: IDLE printing no longer fails if there are spaces or other
special characters in the file path.
special characters in the file path.
...
...
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