Page 1 of 1

'inline:' can't read from standard input

Posted: 2014-05-27T22:00:48-07:00
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.

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

Posted: 2014-05-27T22:03:39-07:00
by dlemstra
You could put it in a [ code ] [ /code ] block.

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

Posted: 2014-06-01T22:03:23-07:00
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;

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

Posted: 2014-06-02T04:00:39-07:00
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.