mirror of
git://github.com/kovidgoyal/calibre.git
synced 2025-12-23 06:45:55 +01:00
MOBI metadata: Gracefully refuse to set metadata on invalid MOBI files
This commit is contained in:
commit
374badc1ba
1 changed files with 5 additions and 0 deletions
|
|
@ -97,9 +97,14 @@ def __init__(self, stream):
|
|||
|
||||
self.nrecs, = unpack('>H', data[76:78])
|
||||
record0 = self.record0 = self.record(0)
|
||||
mobi_header_length, = unpack('>I', record0[0x14:0x18])
|
||||
if not mobi_header_length:
|
||||
raise MobiError("Non-standard file format. Try 'Convert E-Books' with MOBI as Input and Output formats.")
|
||||
|
||||
self.encryption_type, = unpack('>H', record0[12:14])
|
||||
codepage, = unpack('>I', record0[28:32])
|
||||
self.codec = 'utf-8' if codepage == 65001 else 'cp1252'
|
||||
|
||||
image_base, = unpack('>I', record0[108:112])
|
||||
flags, = self.flags, = unpack('>I', record0[128:132])
|
||||
have_exth = self.have_exth = (flags & 0x40) != 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue