Page MenuHomePhabricator

Error reading png file when passed to `convert` command
Closed, InvalidPublic

Description

Thumbor throws this error when trying to thumbnail this image. This bug exists on old (metal) and new (k8s) thumbor and was only caught due to the new logging.

Source original image here

2023-01-16 11:11:32,081 ???? thumbor:ERROR [BaseHander.finish_request] Failed to convert image b"convert: no images defined `png:-' @ error/convert.c/ConvertImageCommand/3258.\n"
Traceback (most recent call last):
  File "/opt/lib/python/site-packages/thumbor/handlers/__init__.py", line 567, in finish_request
    operation=functools.partial(self._load_results, context),
  File "/opt/lib/python/site-packages/thumbor/threadpool.py", line 53, in queue
    return await self._execute_in_foreground(operation, *args)
  File "/opt/lib/python/site-packages/thumbor/threadpool.py", line 45, in _execute_in_foreground
    return operation(*args)
  File "/opt/lib/python/site-packages/thumbor/handlers/__init__.py", line 486, in _load_results
    results = context.request.engine.read(image_extension, quality)
  File "/srv/service/wikimedia_thumbor/engine/proxy/proxy.py", line 139, in read
    ret = self.__getattr__('read')(extension, quality)
  File "/srv/service/wikimedia_thumbor/engine/imagemagick/imagemagick.py", line 330, in read
    raise ImageMagickException('Failed to convert image %s' % stderr)  # pragma: no cover
wikimedia_thumbor.engine.imagemagick.imagemagick.ImageMagickException: Failed to convert image b"convert: no images defined `png:-' @ error/convert.c/ConvertImageCommand/3258.\n"
2023-01-16 11:11:32,090 ???? thumbor:WARNING Error while trying to fetch the image: Failed to convert image b"convert: no images defined `png:-' @ error/convert.c/ConvertImageCommand/3258.\n"

Annoyingly we don't get the same command output here as in T327937, but this is a more complex case. Based on a reading of the code, this is the result of the thumbnail generation failing and then failing completely as opposed to partially. Worryingly we have found a case that this line references # Haven't been able to find a test file that meets this criteria.

It appears that this isn't related to our code itself but actually in the behaviour of convert as regards the file in question. The error seen above is what happens when insufficient arguments are given to convert, and the same can be seen here:

runuser@70658a454946:/tmp$ convert -resize 300 Earth_Impact_Database_world_map.svg # note missing argument here 
convert-im6.q16: no images defined `Earth_Impact_Database_world_map.svg' @ error/convert.c/ConvertImageCommand/3258.
runuser@70658a454946:/tmp$ convert -resize 300 "UitlitéVsPénibilité-François-Dominique.png" abcd.png # sufficient arguments provided here, weird? 
convert-im6.q16: no images defined `abcd.png' @ error/convert.c/ConvertImageCommand/3258.

Note the reference to png:- is expected - this is us hoping to emit the image via stdout:

      By default, the image format of `file' is determined by its magic number.  To specify a particular image format, precede the filename with an image format
name and a colon (i.e. ps:image) or specify the image type as the filename suffix (i.e. image.ps).  Specify 'file' as '-' for standard input or output.

Event Timeline

hnowlan renamed this task from Error reading png file to Error reading png file when passed to `convert` command .Jan 25 2023, 6:19 PM

Image in question is partially corrupt or otherwise an invalid PNG:

root@92a6c8099f72:/tmp# pngcheck -v UitlitéVsPénibilité.png
File: UitlitéVsPénibilité.png (7283 bytes)
  chunk IHDR at offset 0x0000c, length 13
    584 x 510 image, 24-bit RGB, non-interlaced
  chunk pHYs at offset 0x00025, length 9: 7559x7559 pixels/meter (192 dpi)
  chunk IDAT at offset 0x0003a, length 7205
    zlib: deflated, 8K window, default compression
    zlib: inflate error = -3 (data error)
ERRORS DETECTED in UitlitéVsPénibilité.png
root@92a6c8099f72:/tmp# pngcheck -vv UitlitéVsPénibilité.png
File: UitlitéVsPénibilité.png (7283 bytes)
  chunk IHDR at offset 0x0000c, length 13
    584 x 510 image, 24-bit RGB, non-interlaced
  chunk pHYs at offset 0x00025, length 9: 7559x7559 pixels/meter (192 dpi)
  chunk IDAT at offset 0x0003a, length 7205
    zlib: deflated, 8K window, default compression
    row filters (0 none, 1 sub, 2 up, 3 avg, 4 paeth):
      1 4 4 2 2 4 4 4 4 2 4 4 4 4 4 4 2 4 2
    zlib: inflate error = -3 (data error)
 (19 out of 510)
ERRORS DETECTED in UitlitéVsPénibilité.png

convert could be more helpful in telling us this (even when given -verbose we get no indication that there's an error with the file), but it's not our problem as such. We should have a means by which to check an image for validity.