From 07eae119c7cdc15b9d628a4c1c499189c518abc4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 17 May 2010 09:43:33 -0600 Subject: [PATCH] EPUB Input: Handle malformed UUID in EPUB with obfuscated fonts. Fixes #5552 (cannot open or convert ebooks) --- src/calibre/ebooks/epub/input.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/epub/input.py b/src/calibre/ebooks/epub/input.py index 0f94fb674a..5c4e255177 100644 --- a/src/calibre/ebooks/epub/input.py +++ b/src/calibre/ebooks/epub/input.py @@ -37,8 +37,13 @@ class EPUBInput(InputFormatPlugin): scheme = item.get(xkey) if (scheme and scheme.lower() == 'uuid') or \ (item.text and item.text.startswith('urn:uuid:')): - key = str(item.text).rpartition(':')[-1] - key = list(map(ord, uuid.UUID(key).bytes)) + try: + key = str(item.text).rpartition(':')[-1] + key = list(map(ord, uuid.UUID(key).bytes)) + except: + import traceback + traceback.print_exc() + key = None try: root = etree.parse(encfile) @@ -49,7 +54,7 @@ class EPUBInput(InputFormatPlugin): cr = em.getparent().xpath('descendant::*[contains(name(), "CipherReference")]')[0] uri = cr.get('URI') path = os.path.abspath(os.path.join(os.path.dirname(encfile), '..', *uri.split('/'))) - if os.path.exists(path): + if key is not None and os.path.exists(path): self._encrypted_font_uris.append(uri) self.decrypt_font(key, path) return True