'inline:' can't read from standard input

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
mozkeeler
Posts: 2
Joined: 2014-05-27T21:49:38-07:00
Authentication code: 6789

'inline:' can't read from standard input

Post by mozkeeler »

Consider the following inline image data: data:,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAD0lEQVR4AQEEAPv/AAAAAAAEAAFlScNgAAAAAElFTkSuQmCC
This works fine:

Code: Select all

convert inline:data:,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAD0lEQVR4AQEEAPv/AAAAAAAEAAFlScNgAAAAAElFTkSuQmCC out.gif
This does not:

Code: Select all

echo -n "data:,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAD0lEQVR4AQEEAPv/AAAAAAAEAAFlScNgAAAAAElFTkSuQmCC" | convert inline:- out.gif
This gives the error messages:
convert: memory allocation failed `-' @ error/inline.c/ReadINLINEImage/160.
convert: no images defined `out.gif' @ error/convert.c/ConvertImageCommand/3106.

As far as I can tell, the issue is that ReadINLINEImage reads chunks of data of size the minimum of (GetBlobSize(image), MagickMaxBufferExtent). GetBlobSize seems to return 0 for some stream types (which makes sense, as the size of stdin isn't necessarily knowable). Given that it tries to allocate and then read chunks of size 0, ReadINLINEImage fails.
I have a patch with what I think is a reasonable solution, but I don't know how to attach it here.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: 'inline:' can't read from standard input

Post by dlemstra »

You could put it in a [ code ] [ /code ] block.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
mozkeeler
Posts: 2
Joined: 2014-05-27T21:49:38-07:00
Authentication code: 6789

Re: 'inline:' can't read from standard input

Post by mozkeeler »

Ok, here's the result of `svn diff coders/`:

Code: Select all

Index: coders/inline.c
===================================================================
--- coders/inline.c     (revision 15903)
+++ coders/inline.c     (working copy)
@@ -107,6 +107,9 @@
     i;
 
   size_t
+    image_blob_size;
+
+  size_t
     quantum;
 
   ssize_t
@@ -134,7 +137,13 @@
       image=DestroyImageList(image);
       return((Image *) NULL);
     }
-  quantum=MagickMin((size_t) GetBlobSize(image),MagickMaxBufferExtent);
+  image_blob_size=GetBlobSize(image);
+  /* GetBlobSize may return 0 for some stream types, even if there is data */
+  if (image_blob_size == 0)
+    {
+      image_blob_size=MagickMaxBufferExtent;
+    }
+  quantum=MagickMin(image_blob_size,MagickMaxBufferExtent);
   inline_image=(unsigned char *) AcquireQuantumMemory(quantum,
     sizeof(*inline_image));
   count=0;
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: 'inline:' can't read from standard input

Post by magick »

We can reproduce the problem you posted and have a patch in ImageMagick 6.8.9-3 Beta available by sometime tomorrow. Thanks.
Post Reply