Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ZipFile can throw UnicodeDecodeError if zipfile contains bad unic…
…ode (#77)
  • Loading branch information
worr authored and sevein committed May 18, 2016
1 parent dd613fe commit 943a133
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion fido/package.py
Expand Up @@ -77,7 +77,7 @@ def detect_formats(self):
"""Detect available formats inside the ZIP container."""
try:
zip_ = zipfile.ZipFile(self.zip)
except (zipfile.BadZipfile, RuntimeError):
except (zipfile.BadZipfile, RuntimeError, UnicodeDecodeError):
return []

results = []
Expand Down
Binary file added tests/fixtures/unicode.zip
Binary file not shown.
15 changes: 5 additions & 10 deletions tests/test_package.py
Expand Up @@ -9,13 +9,8 @@
FIXTURES_DIR = os.path.normpath(os.path.join(__file__, '..', 'fixtures'))


def test_bad_zip():
p = ZipPackage(os.path.join(FIXTURES_DIR, 'bad.zip'), {})
r = p.detect_formats()
assert isinstance(r, list) and len(r) == 0


def test_worse_zip():
p = ZipPackage(os.path.join(FIXTURES_DIR, 'worse.zip'), {})
r = p.detect_formats()
assert isinstance(r, list) and len(r) == 0
def test_bad_zips():
for filename in ('bad.zip', 'worse.zip', 'unicode.zip'):
p = ZipPackage(os.path.join(FIXTURES_DIR, filename), {})
r = p.detect_formats()
assert isinstance(r, list) and len(r) == 0

0 comments on commit 943a133

Please sign in to comment.