模块崩溃时未处理Python异常

时间:2019-05-30 21:48:19

标签: python exception crash imagemagick wand

我正在通过魔杖导入ImageMagick:from wand.image import Image 然后我用它来从图像中获取数据:

try :
    with Image(filename='./my_image.png') as img:
        sys.stderr.write('SHA-256 message digest for the image pixel stream : ' + img.signature + '\n')
except :
    print("Oops! ",sys.exc_info()[0]," occured.")

但是图像格式错误(this one for example),异常无法正确处理,脚本崩溃并显示以下消息:

  

python:../../magick/quantum.c:216:DestroyQuantumInfo:断言'quantum_info!=(QuantumInfo *)NULL'失败。

Here is the doc about Wand Image signature

为什么异常处理不正确?

我使用的ImageMagick版本(我想这是我使用的Ubuntu 18.04.2 LTS中的默认版本):

$ identify --version
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP 
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff wmf x xml zlib

如评论中所建议,我正在寻找ImageMagick错误:

$ identify -debug All line-numbers.png 
2019-05-31T16:20:42+02:00 0:00.000 0.000u 6.9.7 Configure identify-im6.q16[30840]: utility.c/ExpandFilenames/940/Configure
  Command line: identify {-debug} {All} {line-numbers.png}
2019-05-31T16:20:42+02:00 0:00.000 0.000u 6.9.7 Configure identify-im6.q16[30840]: configure.c/GetConfigureOptions/685/Configure
  Searching for configure file: "/usr/share/ImageMagick-6/coder.xml"
2019-05-31T16:20:42+02:00 0:00.000 0.000u 6.9.7 Configure identify-im6.q16[30840]: configure.c/GetConfigureOptions/685/Configure
  Searching for configure file: "/usr/lib/x86_64-linux-gnu/ImageMagick-6.9.7//config-Q16/coder.xml"
2019-05-31T16:20:42+02:00 0:00.000 0.000u 6.9.7 Configure identify-im6.q16[30840]: configure.c/GetConfigureOptions/685/Configure
  Searching for configure file: "/etc/ImageMagick-6/coder.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Configure identify-im6.q16[30840]: configure.c/GetConfigureOptions/685/Configure
  Searching for configure file: "/usr/share/doc/imagemagick-6-common/htmlcoder.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Configure identify-im6.q16[30840]: configure.c/GetConfigureOptions/685/Configure
  Searching for configure file: "/home/username/.config/ImageMagick/coder.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Configure identify-im6.q16[30840]: configure.c/GetConfigureOptions/685/Configure
  Searching for configure file: "/home/username/.magick/coder.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Configure identify-im6.q16[30840]: coder.c/LoadCoderCache/826/Configure
  Loading coder configuration file "/etc/ImageMagick-6/coder.xml" ...
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Module identify-im6.q16[30840]: module.c/OpenModule/1288/Module
  Searching for module "PNG" using filename "png.la"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Module identify-im6.q16[30840]: module.c/GetMagickModulePath/558/Module
  Searching for coder module file "png.la" ...
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Module identify-im6.q16[30840]: module.c/OpenModule/1297/Module
  Opening module at path "/usr/lib/x86_64-linux-gnu/ImageMagick-6.9.7//modules-Q16/coders/png.la"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Module identify-im6.q16[30840]: module.c/OpenModule/1324/Module
  Method "RegisterPNGImage" in module "PNG" at address 0x7fac6c16f1c0
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Module identify-im6.q16[30840]: module.c/OpenModule/1338/Module
  Method "UnregisterPNGImage" in module "PNG" at address 0x7fac6c16f770
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Policy identify-im6.q16[30840]: policy.c/IsRightsAuthorized/580/Policy
  Domain: Path; rights=Read; pattern="line-numbers.png" ...
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Blob identify-im6.q16[30840]: blob.c/OpenBlob/2593/Blob
    read 3 magic header bytes
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Configure identify-im6.q16[30840]: configure.c/GetConfigureOptions/685/Configure
  Searching for configure file: "/usr/share/ImageMagick-6/magic.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Configure identify-im6.q16[30840]: configure.c/GetConfigureOptions/685/Configure
  Searching for configure file: "/usr/lib/x86_64-linux-gnu/ImageMagick-6.9.7//config-Q16/magic.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Configure identify-im6.q16[30840]: configure.c/GetConfigureOptions/685/Configure
  Searching for configure file: "/etc/ImageMagick-6/magic.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Configure identify-im6.q16[30840]: configure.c/GetConfigureOptions/685/Configure
  Searching for configure file: "/usr/share/doc/imagemagick-6-common/htmlmagic.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Configure identify-im6.q16[30840]: configure.c/GetConfigureOptions/685/Configure
  Searching for configure file: "/home/username/.config/ImageMagick/magic.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Configure identify-im6.q16[30840]: configure.c/GetConfigureOptions/685/Configure
  Searching for configure file: "/home/username/.magick/magic.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Configure identify-im6.q16[30840]: magic.c/LoadMagicCache/794/Configure
  Loading magic configure file "/etc/ImageMagick-6/magic.xml" ...
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Policy identify-im6.q16[30840]: policy.c/IsRightsAuthorized/580/Policy
  Domain: Coder; rights=Read; pattern="PNG" ...
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Policy identify-im6.q16[30840]: policy.c/IsRightsAuthorized/580/Policy
  Domain: Path; rights=Read; pattern="line-numbers.png" ...
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Blob identify-im6.q16[30840]: blob.c/OpenBlob/2593/Blob
    read 3 magic header bytes
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Coder identify-im6.q16[30840]: png.c/ReadPNGImage/3940/Coder
  Enter ReadPNGImage()
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Policy identify-im6.q16[30840]: policy.c/IsRightsAuthorized/580/Policy
  Domain: Path; rights=Read; pattern="line-numbers.png" ...
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Blob identify-im6.q16[30840]: blob.c/OpenBlob/2593/Blob
    read 3 magic header bytes
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Coder identify-im6.q16[30840]: png.c/ReadOnePNGImage/2042/Coder
    Enter ReadOnePNGImage()
    IM version     = 6.9.7-4
    Libpng version = 1.6.34
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Coder identify-im6.q16[30840]: png.c/ReadOnePNGImage/2055/Coder
      Zlib version   = 1.2.11
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Coder identify-im6.q16[30840]: png.c/ReadOnePNGImage/2085/Coder
      Before reading:
      image->matte=0
      image->rendering_intent=2
      image->colorspace=13
      image->gamma=0.454545
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Coder identify-im6.q16[30840]: png.c/MagickPNGWarningHandler/1651/Coder
    libpng-1.6.34 warning: Image height exceeds user limit in IHDR
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Locale identify-im6.q16[30840]: locale.c/GetLocaleOptions/824/Locale
  Searching for locale file: "/usr/share/ImageMagick-6/locale.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Locale identify-im6.q16[30840]: locale.c/GetLocaleOptions/824/Locale
  Searching for locale file: "/usr/lib/x86_64-linux-gnu/ImageMagick-6.9.7//config-Q16/locale.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Locale identify-im6.q16[30840]: locale.c/GetLocaleOptions/824/Locale
  Searching for locale file: "/etc/ImageMagick-6/locale.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Locale identify-im6.q16[30840]: locale.c/GetLocaleOptions/824/Locale
  Searching for locale file: "/usr/share/doc/imagemagick-6-common/htmllocale.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Locale identify-im6.q16[30840]: locale.c/GetLocaleOptions/824/Locale
  Searching for locale file: "/home/username/.config/ImageMagick/locale.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Locale identify-im6.q16[30840]: locale.c/GetLocaleOptions/824/Locale
  Searching for locale file: "/home/username/.magick/locale.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Configure identify-im6.q16[30840]: locale.c/LoadLocaleCache/1177/Configure
  Loading locale configure file "/usr/share/ImageMagick-6/locale.xml" ...
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Locale identify-im6.q16[30840]: locale.c/GetLocaleOptions/824/Locale
  Searching for locale file: "/usr/share/ImageMagick-6/english.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Locale identify-im6.q16[30840]: locale.c/GetLocaleOptions/824/Locale
  Searching for locale file: "/usr/lib/x86_64-linux-gnu/ImageMagick-6.9.7//config-Q16/english.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Locale identify-im6.q16[30840]: locale.c/GetLocaleOptions/824/Locale
  Searching for locale file: "/etc/ImageMagick-6/english.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Locale identify-im6.q16[30840]: locale.c/GetLocaleOptions/824/Locale
  Searching for locale file: "/usr/share/doc/imagemagick-6-common/htmlenglish.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Locale identify-im6.q16[30840]: locale.c/GetLocaleOptions/824/Locale
  Searching for locale file: "/home/username/.config/ImageMagick/english.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Locale identify-im6.q16[30840]: locale.c/GetLocaleOptions/824/Locale
  Searching for locale file: "/home/username/.magick/english.xml"
2019-05-31T16:20:42+02:00 0:00.010 0.000u 6.9.7 Configure identify-im6.q16[30840]: locale.c/LoadLocaleCache/1177/Configure
  Loading locale configure file "/usr/share/ImageMagick-6/english.xml" ...
2019-05-31T16:20:42+02:00 0:00.020 0.000u 6.9.7 Exception identify-im6.q16[30840]: png.c/MagickPNGWarningHandler/1654/Exception
  Image height exceeds user limit in IHDR `line-numbers.png'
2019-05-31T16:20:42+02:00 0:00.020 0.000u 6.9.7 Coder identify-im6.q16[30840]: png.c/MagickPNGErrorHandler/1625/Coder
    libpng-1.6.34 error: Invalid IHDR data
2019-05-31T16:20:42+02:00 0:00.020 0.000u 6.9.7 Exception identify-im6.q16[30840]: png.c/MagickPNGErrorHandler/1628/Exception
  Invalid IHDR data `line-numbers.png'
identify: ../../magick/quantum.c :216 : DestroyQuantumInfo:  l'assertion « quantum_info != (QuantumInfo *) NULL » a échoué.
Abandon

0 个答案:

没有答案