diff options
| author | Eduard Braun <eduard.braun2@gmx.de> | 2017-09-30 14:46:21 +0000 |
|---|---|---|
| committer | Eduard Braun <eduard.braun2@gmx.de> | 2017-09-30 20:21:17 +0000 |
| commit | 1fe5b815e10ade11fbb4bbec6b15f1a8945b7a1b (patch) | |
| tree | a055e421ee4a0003fbf36e0a5fc7718641ae0131 /src | |
| parent | Fix bug #1719505 segfault on convert to path (diff) | |
| download | inkscape-1fe5b815e10ade11fbb4bbec6b15f1a8945b7a1b.tar.gz inkscape-1fe5b815e10ade11fbb4bbec6b15f1a8945b7a1b.zip | |
Do not crash if raster image can not be opened by ImageMagick
The crash only affected embedded images.
(we were already catching the exception when loading a linked file)
While at it add some error reporting via debug messages,
fix a memory leak and do some minor cleanup.
Fixed bug:
- https://bugs.launchpad.net/inkscape/+bug/1720330
Diffstat (limited to 'src')
| -rw-r--r-- | src/extension/internal/bitmap/imagemagick.cpp | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/extension/internal/bitmap/imagemagick.cpp b/src/extension/internal/bitmap/imagemagick.cpp index cc5b3d1bc..352271e26 100644 --- a/src/extension/internal/bitmap/imagemagick.cpp +++ b/src/extension/internal/bitmap/imagemagick.cpp @@ -39,7 +39,7 @@ namespace Bitmap { class ImageMagickDocCache: public Inkscape::Extension::Implementation::ImplementationDocumentCache { friend class ImageMagick; private: - void readImage(char const *xlink, Magick::Image *image); + void readImage(char const *xlink, char const *id, Magick::Image *image); protected: Inkscape::XML::Node** _nodes; @@ -85,11 +85,12 @@ ImageMagickDocCache::ImageMagickDocCache(Inkscape::UI::View::View * view) : { _nodes[_imageCount] = node; char const *xlink = node->attribute("xlink:href"); + char const *id = node->attribute("id"); _originals[_imageCount] = xlink; _caches[_imageCount] = (char*)""; _cacheLengths[_imageCount] = 0; _images[_imageCount] = new Magick::Image(); - readImage(xlink, _images[_imageCount]); + readImage(xlink, id, _images[_imageCount]); _imageItems[_imageCount] = item; _imageCount++; } @@ -113,26 +114,33 @@ ImageMagickDocCache::~ImageMagickDocCache ( ) { } void -ImageMagickDocCache::readImage(const char *xlink, Magick::Image *image) +ImageMagickDocCache::readImage(const char *xlink, const char *id, Magick::Image *image) { // Find if the xlink:href is base64 data, i.e. if the image is embedded - char *search = (char *) g_strndup(xlink, 30); + gchar *search = g_strndup(xlink, 30); if (strstr(search, "base64") != (char*)NULL) { // 7 = strlen("base64") + strlen(",") const char* pureBase64 = strstr(xlink, "base64") + 7; Magick::Blob blob; blob.base64(pureBase64); - image->read(blob); - } - else { - const gchar *path = xlink; - if (strncmp (xlink,"file:", 5) == 0) { - path = g_filename_from_uri(xlink, NULL, NULL); + try { + image->read(blob); + } catch (Magick::Exception &error_) { + g_warning("ImageMagick could not read '%s'\nDetails: %s", id, error_.what()); + } + } else { + gchar *path; + if (strncmp (xlink,"file:", 5) == 0) { + path = g_filename_from_uri(xlink, NULL, NULL); + } else { + path = g_strdup(xlink); } - try { image->read(path); - } catch (...) {} + } catch (Magick::Exception &error_) { + g_warning("ImageMagick could not read '%s' from '%s'\nDetails: %s", id, path, error_.what()); + } + g_free(path); } g_free(search); } |
