MOBI metadata: Do not try to extarct embedded metadata from MOBI files larger than 4MB

This commit is contained in:
Kovid Goyal 2010-02-21 13:33:49 -07:00
parent 6b04e57275
commit eae6bf3608

View File

@ -10,6 +10,7 @@ import re
import struct import struct
import textwrap import textwrap
import cStringIO import cStringIO
import sys
try: try:
from PIL import Image as PILImage from PIL import Image as PILImage
@ -806,6 +807,13 @@ def get_metadata(stream):
if mh.exth.mi is not None: if mh.exth.mi is not None:
mi = mh.exth.mi mi = mh.exth.mi
else: else:
size = sys.maxint
if hasattr(stream, 'seek') and hasattr(stream, 'tell'):
pos = stream.tell()
stream.seek(0, 2)
size = stream.tell()
stream.seek(pos)
if size < 4*1024*1024:
with TemporaryDirectory('_mobi_meta_reader') as tdir: with TemporaryDirectory('_mobi_meta_reader') as tdir:
with CurrentDir(tdir): with CurrentDir(tdir):
mr = MobiReader(stream, log) mr = MobiReader(stream, log)