mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
AZW3 Input: Fix crash when processing AZW3 files that contain certain SVG images dies to a bug in ImageMagick. See #1384375 (svg cover lost when converting ePub->AZW3)
This commit is contained in:
parent
4a5ac17482
commit
41ce07ea7a
@ -10,10 +10,10 @@ def what(file, h=None):
|
|||||||
if h is None:
|
if h is None:
|
||||||
if isinstance(file, basestring):
|
if isinstance(file, basestring):
|
||||||
f = open(file, 'rb')
|
f = open(file, 'rb')
|
||||||
h = f.read(44)
|
h = f.read(150)
|
||||||
else:
|
else:
|
||||||
location = file.tell()
|
location = file.tell()
|
||||||
h = file.read(44)
|
h = file.read(150)
|
||||||
file.seek(location)
|
file.seek(location)
|
||||||
f = None
|
f = None
|
||||||
else:
|
else:
|
||||||
@ -132,6 +132,12 @@ def test_emf(h, f):
|
|||||||
|
|
||||||
tests.append(test_emf)
|
tests.append(test_emf)
|
||||||
|
|
||||||
|
def test_svg(h, f):
|
||||||
|
if (h[:2] == b'<?' and h[2:5].lower() == 'xml' and b'<svg' in h) or h.startswith(b'<svg'):
|
||||||
|
return 'svg'
|
||||||
|
|
||||||
|
tests.append(test_svg)
|
||||||
|
|
||||||
# --------------------#
|
# --------------------#
|
||||||
# Small test program #
|
# Small test program #
|
||||||
# --------------------#
|
# --------------------#
|
||||||
|
@ -137,6 +137,9 @@ def identify_data(data):
|
|||||||
(width, height, format)
|
(width, height, format)
|
||||||
or raises an Exception if data is not an image.
|
or raises an Exception if data is not an image.
|
||||||
'''
|
'''
|
||||||
|
if data.startswith(b'<?xml'):
|
||||||
|
# ImageMagick segfaults when trying to identify SVG images
|
||||||
|
raise ValueError('Identifying svg images is not supported')
|
||||||
img = Image()
|
img = Image()
|
||||||
if hasattr(img, 'identify'):
|
if hasattr(img, 'identify'):
|
||||||
img.identify(data)
|
img.identify(data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user