diff --git a/src/calibre/ebooks/mobi/reader/markup.py b/src/calibre/ebooks/mobi/reader/markup.py index 03e65951b4..26583cf30c 100644 --- a/src/calibre/ebooks/mobi/reader/markup.py +++ b/src/calibre/ebooks/mobi/reader/markup.py @@ -154,8 +154,8 @@ def update_flow_links(mobi8_reader, resource_map, log): 'valid font in %s' % (num, tag)) else: replacement = '"%s"'%('../'+ href) - if href.endswith('.dat'): - replacement = 'unable-to-extract.ttf' + if href.endswith('.failed'): + replacement = '"%s"'%('failed-'+href) tag = font_index_pattern.sub(replacement, tag, 1) # process links to other css pieces diff --git a/src/calibre/ebooks/mobi/reader/mobi8.py b/src/calibre/ebooks/mobi/reader/mobi8.py index e459287331..d1f7ae93d9 100644 --- a/src/calibre/ebooks/mobi/reader/mobi8.py +++ b/src/calibre/ebooks/mobi/reader/mobi8.py @@ -353,14 +353,18 @@ class Mobi8Reader(object): fields = None #self.log.debug('Font record fields: %s'%(fields,)) cdata = data[26:-4] + ext = 'dat' try: uncompressed_data = zlib.decompress(cdata, -15) except: self.log.warn('Failed to uncompress embedded font %d: ' 'Fields: %s' % (fname_idx, fields,)) uncompressed_data = data[4:] + ext = 'failed' hdr = uncompressed_data[0:4] - ext = 'dat' + if len(uncompressed_data) < 200: + self.log.warn('Corrupted font record: %d'%fname_idx) + ext = 'failed' if hdr == b'\0\1\0\0' or hdr == b'true' or hdr == b'ttcf': ext = 'ttf' href = "fonts/%05d.%s" % (fname_idx, ext)