From 0f6603dcf6e429236cb0a66c70e32c2d3e606b44 Mon Sep 17 00:00:00 2001 From: Alan D Moore Date: Mon, 23 Oct 2017 14:34:12 -0500 Subject: [PATCH] Display an error when ISO is invalid Previous behavior was to crash the program when an iso file was unreadable or had 0 length. This patch has the program display an error dialog and not select the file. --- scripts/iso.py | 10 +++++++++- scripts/isodump3.py | 5 ++++- scripts/mbusb_gui.py | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/scripts/iso.py b/scripts/iso.py index 6c46fbf..93a20c8 100644 --- a/scripts/iso.py +++ b/scripts/iso.py @@ -60,12 +60,20 @@ def iso_size(iso_link): return os.path.getsize(iso_link) +def is_readable(iso_link): + return os.access(iso_link, os.R_OK) + + def is_bootable(iso_link): """ Check if an ISO has the ability to boot. :return: True if ISO is bootable and False if not. """ - iso9660fs = ISO9660(iso_link) + try: + iso9660fs = ISO9660(iso_link) + except IOError as e: + log(str(e)) + raise isBootable = iso9660fs.checkISOBootable() return bool(isBootable) diff --git a/scripts/isodump3.py b/scripts/isodump3.py index 5d46fdf..8c53675 100644 --- a/scripts/isodump3.py +++ b/scripts/isodump3.py @@ -106,7 +106,10 @@ class ISO9660: f = open(isofile, 'rb') except(IOError): sys.stderr.write("can't open {0}".format(isofile)) - sys.exit(-1) + raise + + if os.path.getsize(isofile) == 0: + raise IOError("File {0} appears to be empty".format(isofile)) self.isoFile = f self.priVol = None diff --git a/scripts/mbusb_gui.py b/scripts/mbusb_gui.py index a2fa7b2..7e9cb9f 100644 --- a/scripts/mbusb_gui.py +++ b/scripts/mbusb_gui.py @@ -214,6 +214,22 @@ Are you SURE you want to enable it?", 'Img Files(*.img);; All Files(*.*)')[0] if config.image_path: + # sanity checks + if not is_readable(config.image_path): + QtWidgets.QMessageBox.critical( + self, + "ISO Not readable", + "Sorry, the file \"{0}\" is not readable.".format(config.image_path) + ) + return + if iso_size(config.image_path) == 0: + QtWidgets.QMessageBox.critical( + self, + "ISO is an empty file", + "Sorry, the file \"{0}\" contains no data.".format(config.image_path) + ) + return + default_dir_path = os.path.dirname(config.image_path) gen.write_to_file(preference_file_path, default_dir_path)