From fb409b5db431103a6885e8b7d12e5b425c19a66d Mon Sep 17 00:00:00 2001 From: Iris Morelle Date: Wed, 27 Jun 2018 03:40:25 -0400 Subject: [PATCH] wmllint: Leave gzipped binary files alone, they're not safe for consumption Fixes wmllint crashing like this upon encountering a gzip tarball in an add-on: Traceback (most recent call last): File "/home/shadowm/bin/wmllint-1.14", line 3188, in for fn in allcfgfiles(directory): File "/home/shadowm/bin/wmllint-1.14", line 2944, in allcfgfiles if interesting(os.path.join(root, name)): File "/home/shadowm/bin/wmllint-1.14", line 2927, in interesting return fn.endswith(".cfg") or is_map(fn) or issave(fn) File "/home/shadowm/src/wesnoth-1.14/data/tools/wesnoth/wmltools3.py", line 270, in issave return firstline.startswith("label=") TypeError: startswith first arg must be bytes or a tuple of bytes, not str [ci skip] (cherry-picked from commit c92e167a14229ed0d9b6f16f1d1ca31cacd292cd) --- changelog.md | 1 + data/tools/wesnoth/wmltools3.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/changelog.md b/changelog.md index 9879b8b3a640..21f1dd0c8866 100644 --- a/changelog.md +++ b/changelog.md @@ -82,6 +82,7 @@ selection dialog is dismissed. * Fixed an issue with positioned sound sources ignoring the volume set in Preferences after going off the audible radius and back (issue #3280). + * Fixed wmllint choking on gzipped binary files (e.g. gzipped tarballs). ## Version 1.14.3 ### AI diff --git a/data/tools/wesnoth/wmltools3.py b/data/tools/wesnoth/wmltools3.py index ae1d4f560683..5633634c78ed 100644 --- a/data/tools/wesnoth/wmltools3.py +++ b/data/tools/wesnoth/wmltools3.py @@ -260,6 +260,9 @@ def issave(filename): if filename.endswith(".gz"): with gzip.open(filename) as content: firstline = content.readline() + if not isinstance(firstline, str): + # It's a compressed binary file + return False else: try: with codecs.open(filename, "r", "utf8") as content: