Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
8f1fefab
Kaydet (Commit)
8f1fefab
authored
Kas 17, 2012
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #16408: Fix file descriptors not being closed in error conditions in the zipfile module.
Patch by Serhiy Storchaka.
üst
5439458a
8572da5e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
44 deletions
+30
-44
zipfile.py
Lib/zipfile.py
+27
-44
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/zipfile.py
Dosyayı görüntüle @
8f1fefab
...
...
@@ -906,8 +906,9 @@ class ZipFile:
self
.
fp
=
file
self
.
filename
=
getattr
(
file
,
'name'
,
None
)
try
:
if
key
==
'r'
:
self
.
_
GetContents
()
self
.
_Real
GetContents
()
elif
key
==
'w'
:
# set the modified flag so central directory gets written
# even if no files are added to the archive
...
...
@@ -926,10 +927,13 @@ class ZipFile:
# even if no files are added to the archive
self
.
_didModify
=
True
else
:
if
not
self
.
_filePassed
:
self
.
fp
.
close
()
self
.
fp
=
None
raise
RuntimeError
(
'Mode must be "r", "w" or "a"'
)
except
:
fp
=
self
.
fp
self
.
fp
=
None
if
not
self
.
_filePassed
:
fp
.
close
()
raise
def
__enter__
(
self
):
return
self
...
...
@@ -937,17 +941,6 @@ class ZipFile:
def
__exit__
(
self
,
type
,
value
,
traceback
):
self
.
close
()
def
_GetContents
(
self
):
"""Read the directory, making sure we close the file if the format
is bad."""
try
:
self
.
_RealGetContents
()
except
BadZipFile
:
if
not
self
.
_filePassed
:
self
.
fp
.
close
()
self
.
fp
=
None
raise
def
_RealGetContents
(
self
):
"""Read in the table of contents for the ZIP file."""
fp
=
self
.
fp
...
...
@@ -1049,7 +1042,7 @@ class ZipFile:
try
:
# Read by chunks, to avoid an OverflowError or a
# MemoryError with very large embedded files.
f
=
self
.
open
(
zinfo
.
filename
,
"r"
)
with
self
.
open
(
zinfo
.
filename
,
"r"
)
as
f
:
while
f
.
read
(
chunk_size
):
# Check CRC-32
pass
except
BadZipFile
:
...
...
@@ -1113,18 +1106,14 @@ class ZipFile:
else
:
zef_file
=
io
.
open
(
self
.
filename
,
'rb'
)
try
:
# Make sure we have an info object
if
isinstance
(
name
,
ZipInfo
):
# 'name' is already an info object
zinfo
=
name
else
:
# Get info object for name
try
:
zinfo
=
self
.
getinfo
(
name
)
except
KeyError
:
if
not
self
.
_filePassed
:
zef_file
.
close
()
raise
zef_file
.
seek
(
zinfo
.
header_offset
,
0
)
# Skip the file header:
...
...
@@ -1152,8 +1141,6 @@ class ZipFile:
fname_str
=
fname
.
decode
(
"cp437"
)
if
fname_str
!=
zinfo
.
orig_filename
:
if
not
self
.
_filePassed
:
zef_file
.
close
()
raise
BadZipFile
(
'File name in directory
%
r and header
%
r differ.'
%
(
zinfo
.
orig_filename
,
fname
))
...
...
@@ -1165,10 +1152,8 @@ class ZipFile:
if
not
pwd
:
pwd
=
self
.
pwd
if
not
pwd
:
if
not
self
.
_filePassed
:
zef_file
.
close
()
raise
RuntimeError
(
"File
%
s is encrypted, "
"password required for extraction"
%
name
)
raise
RuntimeError
(
"File
%
s is encrypted, password "
"required for extraction"
%
name
)
zd
=
_ZipDecrypter
(
pwd
)
# The first 12 bytes in the cypher stream is an encryption header
...
...
@@ -1185,12 +1170,14 @@ class ZipFile:
# compare against the CRC otherwise
check_byte
=
(
zinfo
.
CRC
>>
24
)
&
0xff
if
h
[
11
]
!=
check_byte
:
if
not
self
.
_filePassed
:
zef_file
.
close
()
raise
RuntimeError
(
"Bad password for file"
,
name
)
return
ZipExtFile
(
zef_file
,
mode
,
zinfo
,
zd
,
close_fileobj
=
not
self
.
_filePassed
)
except
:
if
not
self
.
_filePassed
:
zef_file
.
close
()
raise
def
extract
(
self
,
member
,
path
=
None
,
pwd
=
None
):
"""Extract a member from the archive to the current working directory,
...
...
@@ -1247,11 +1234,9 @@ class ZipFile:
os
.
mkdir
(
targetpath
)
return
targetpath
source
=
self
.
open
(
member
,
pwd
=
pwd
)
target
=
open
(
targetpath
,
"wb"
)
with
self
.
open
(
member
,
pwd
=
pwd
)
as
source
,
\
open
(
targetpath
,
"wb"
)
as
target
:
shutil
.
copyfileobj
(
source
,
target
)
source
.
close
()
target
.
close
()
return
targetpath
...
...
@@ -1411,6 +1396,7 @@ class ZipFile:
if
self
.
fp
is
None
:
return
try
:
if
self
.
mode
in
(
"w"
,
"a"
)
and
self
.
_didModify
:
# write ending records
count
=
0
pos1
=
self
.
fp
.
tell
()
...
...
@@ -1506,10 +1492,11 @@ class ZipFile:
self
.
fp
.
write
(
endrec
)
self
.
fp
.
write
(
self
.
_comment
)
self
.
fp
.
flush
()
if
not
self
.
_filePassed
:
self
.
fp
.
close
()
finally
:
fp
=
self
.
fp
self
.
fp
=
None
if
not
self
.
_filePassed
:
fp
.
close
()
class
PyZipFile
(
ZipFile
):
...
...
@@ -1676,15 +1663,14 @@ def main(args = None):
if
len
(
args
)
!=
2
:
print
(
USAGE
)
sys
.
exit
(
1
)
zf
=
ZipFile
(
args
[
1
],
'r'
)
with
ZipFile
(
args
[
1
],
'r'
)
as
zf
:
zf
.
printdir
()
zf
.
close
()
elif
args
[
0
]
==
'-t'
:
if
len
(
args
)
!=
2
:
print
(
USAGE
)
sys
.
exit
(
1
)
zf
=
ZipFile
(
args
[
1
],
'r'
)
with
ZipFile
(
args
[
1
],
'r'
)
as
zf
:
badfile
=
zf
.
testzip
()
if
badfile
:
print
(
"The following enclosed file is corrupted: {!r}"
.
format
(
badfile
))
...
...
@@ -1695,7 +1681,7 @@ def main(args = None):
print
(
USAGE
)
sys
.
exit
(
1
)
zf
=
ZipFile
(
args
[
1
],
'r'
)
with
ZipFile
(
args
[
1
],
'r'
)
as
zf
:
out
=
args
[
2
]
for
path
in
zf
.
namelist
():
if
path
.
startswith
(
'./'
):
...
...
@@ -1708,7 +1694,6 @@ def main(args = None):
os
.
makedirs
(
tgtdir
)
with
open
(
tgt
,
'wb'
)
as
fp
:
fp
.
write
(
zf
.
read
(
path
))
zf
.
close
()
elif
args
[
0
]
==
'-c'
:
if
len
(
args
)
<
3
:
...
...
@@ -1724,11 +1709,9 @@ def main(args = None):
os
.
path
.
join
(
path
,
nm
),
os
.
path
.
join
(
zippath
,
nm
))
# else: ignore
zf
=
ZipFile
(
args
[
1
],
'w'
,
allowZip64
=
True
)
with
ZipFile
(
args
[
1
],
'w'
,
allowZip64
=
True
)
as
zf
:
for
src
in
args
[
2
:]:
addToZip
(
zf
,
src
,
os
.
path
.
basename
(
src
))
zf
.
close
()
if
__name__
==
"__main__"
:
main
()
Misc/NEWS
Dosyayı görüntüle @
8f1fefab
...
...
@@ -130,6 +130,9 @@ Core and Builtins
Library
-------
- Issue #16408: Fix file descriptors not being closed in error conditions
in the zipfile module. Patch by Serhiy Storchaka.
- Issue #14631: Add a new :class:`weakref.WeakMethod` to simulate weak
references to bound methods.
...
...
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