From bb94a8dbe2936d138256f44a12785ba270a4fe7e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 4 Jan 2012 10:51:37 +0530 Subject: [PATCH] MOBI Input: Fix regression that caused a mixup of images when the MOBI file header contains an incorrect first image index pointer. Fixes #911243 (Private bug) --- src/calibre/ebooks/mobi/debug.py | 4 +++- src/calibre/ebooks/mobi/reader.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/mobi/debug.py b/src/calibre/ebooks/mobi/debug.py index 0b773a51d8..7b04ee57a8 100644 --- a/src/calibre/ebooks/mobi/debug.py +++ b/src/calibre/ebooks/mobi/debug.py @@ -1410,9 +1410,11 @@ class MOBIFile(object): # {{{ self.mobi_header.extra_data_flags, decompress) for r in xrange(1, min(len(self.records), ntr+1))] self.image_records, self.binary_records = [], [] + image_index = 0 for i in xrange(fntbr, len(self.records)): if i in self.indexing_record_nums or i in self.huffman_record_nums: continue + image_index += 1 r = self.records[i] fmt = None if i >= fii and r.raw[:4] not in (b'FLIS', b'FCIS', b'SRCS', @@ -1422,7 +1424,7 @@ class MOBIFile(object): # {{{ except: pass if fmt is not None: - self.image_records.append(ImageRecord(len(self.image_records)+1, r, fmt)) + self.image_records.append(ImageRecord(image_index, r, fmt)) else: self.binary_records.append(BinaryRecord(i, r)) diff --git a/src/calibre/ebooks/mobi/reader.py b/src/calibre/ebooks/mobi/reader.py index e58b492cef..c0a1687eaf 100644 --- a/src/calibre/ebooks/mobi/reader.py +++ b/src/calibre/ebooks/mobi/reader.py @@ -974,12 +974,13 @@ class MobiReader(object): continue processed_records.append(i) data = self.sections[i][0] + image_index += 1 if data[:4] in {b'FLIS', b'FCIS', b'SRCS', b'\xe9\x8e\r\n', b'RESC', b'BOUN', b'FDST', b'DATP', b'AUDI', b'VIDE'}: - # A FLIS, FCIS, SRCS or EOF record, ignore + # This record is a known non image type, not need to try to + # load the image continue buf = cStringIO.StringIO(data) - image_index += 1 try: im = PILImage.open(buf) im = im.convert('RGB')