mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Also prevent ImageMagick identify routine from touching images other than the core types
This commit is contained in:
parent
816063041c
commit
4adb20ebb4
@ -235,6 +235,12 @@ class Image(_magick.Image): # {{{
|
||||
_magick.Image.quantize(self, number_colors, colorspace, treedepth, dither,
|
||||
measure_error)
|
||||
|
||||
def identify(self, data):
|
||||
fmt = what(None, data)
|
||||
if fmt not in {'gif', 'png', 'jpeg', 'jpeg2000', 'webp'}:
|
||||
raise ValueError('Unsupported image format: %s' % fmt)
|
||||
return _magick.Image.identify(self, data)
|
||||
|
||||
def trim(self, fuzz):
|
||||
try:
|
||||
_magick.Image.remove_border(self, fuzz)
|
||||
|
@ -141,9 +141,6 @@ def identify_data(data):
|
||||
(width, height, format)
|
||||
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.identify(data)
|
||||
width, height = img.size
|
||||
@ -156,7 +153,8 @@ def identify(path):
|
||||
(width, height, format)
|
||||
or raises an Exception.
|
||||
'''
|
||||
data = open(path, 'rb').read()
|
||||
with lopen(path, 'rb') as f:
|
||||
data = f.read()
|
||||
return identify_data(data)
|
||||
|
||||
def add_borders_to_image(img_data, left=0, top=0, right=0, bottom=0,
|
||||
|
Loading…
x
Reference in New Issue
Block a user