파이썬에서 이상한 오류가 발생합니다. zip 모듈을 사용하여 암호로 보호 된 파일의 압축을 풀려고하면 "oy"를 암호로 설정하려고 할 때 예외가 발생합니다. 다른 모든 것은 효과가있는 것처럼 보입니다. ZipFile 모듈의 버그?암호로 압축 해제 된 zip 파일이 실패합니다 - Python 버그?
import zipfile
zip = zipfile.ZipFile("file.zip", "r")
zip.setpassword("oy".encode('utf-8'))
zip.extractall() #Above password "oy" generates the error here
zip.close()
입니다 예외가 내가 얻을 :
zlib.error: Error -3 while decompressing: invalid distance too far back
편집 내가 지금 테스트 한 :
Traceback (most recent call last):
File "unzip.py", line 4, in <module>
zip.extractall()
File "C:\Program Files\Python32\lib\zipfile.py", line 1002, in extrac
l
self.extract(zipinfo, path, pwd)
File "C:\Program Files\Python32\lib\zipfile.py", line 990, in extract
return self._extract_member(member, path, pwd)
File "C:\Program Files\Python32\lib\zipfile.py", line 1035, in _extra
member
shutil.copyfileobj(source, target)
File "C:\Program Files\Python32\lib\shutil.py", line 65, in copyfileo
buf = fsrc.read(length)
File "C:\Program Files\Python32\lib\zipfile.py", line 581, in read
data = self.read1(n - len(buf))
File "C:\Program Files\Python32\lib\zipfile.py", line 633, in read1
max(n - len_readbuffer, self.MIN_READ_SIZE)
zlib.error: Error -3 while decompressing: invalid block type
내가 인코딩으로 UTF-16를 사용하는 경우 나는이 오류 다음과 같은 것들을 가진 가상 리눅스 머신 :
- 파이썬 버전 : 2.6.5
- 나는 지금은 문제가 뭔가 다른 것 같다
zip -e file.zip hello.txt
와 암호로 보호 된 zip 파일을 만들었습니다. 이제 암호가 틀린 경우에도 zip 파일을 추출 할 수 있습니다!
try:
zip.setpassword("ks") # "ks" is wrong password but it still extracts the zip
zip.extractall()
except RuntimeException:
print "wrong!"
간혹 잘못된 비밀번호로 압축 파일을 추출 할 수 있습니다. 파일 (압축 파일 안쪽)을 압축 해제하지만 열려고하면 정보가 손상/해독 된 것 같습니다.
참고로 'ZipFile'은 컨텍스트 관리자이므로 열기와 마찬가지로 [the with with statement] (http://docs.python.org/reference/compound_stmts.html#with)를 사용할 수 있습니다. 파일. 더 읽기 쉽고 예외가 발생하더라도 올바르게 닫히는 것을 처리합니다. –
다른 인코딩을 사용해 보셨습니까? utf16? – User
@ user1320237 : 예, 있습니다. 같은 문제. 하지만 다른 암호는 작동하지 않습니다. – Rox