dead-lock in ReadPDFImage, no Exception can be caught

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
Akechi

dead-lock in ReadPDFImage, no Exception can be caught

Post by Akechi »

(gdb) bt
#0 0x007ee402 in ?? ()
#1 0x0028d13e in __lll_mutex_lock_wait () from /lib/tls/libpthread.so.0
#2 0x00289d9b in _L_mutex_lock_35 () from /lib/tls/libpthread.so.0
#3 0xbf7efc78 in ?? ()
#4 0x006d3c74 in ?? () from /usr/local/lib/libMagickCore.so.1
#5 0x0071db70 in instantiate_configure () from /usr/local/lib/libMagickCore.so.1
#6 0x08468cc8 in ?? ()
#7 0xbf7efc88 in ?? ()
#8 0x0064f319 in LockSemaphoreInfo (semaphore_info=0x740a) at magick/semaphore.c:361
#9 0x0064f319 in LockSemaphoreInfo (semaphore_info=0x8468cc8) at magick/semaphore.c:361
#10 0x0064f41e in AcquireSemaphoreInfo (semaphore_info=0x71db70) at magick/semaphore.c:147
#11 0x00582783 in ReadImage (image_info=0x84b0858, exception=0xbf801050) at magick/constitute.c:515
#12 0x002ada25 in ReadPDFImage (image_info=0x846dd88, exception=0xbf801050) at coders/pdf.c:584
#13 0x00582190 in ReadImage (image_info=0x8469c80, exception=0xbf801050) at magick/constitute.c:516
#14 0x00558a51 in BlobToImage (image_info=0x843f1b0, blob=0xb737e008, length=6000000, exception=0xbf801050) at magick/blob.c:376
#15 0x001579ce in Magick::Image::read (this=0xbf8010e0, blob_=@0xbf8010f0) at Magick++/lib/Image.cpp:1578
#16 0x08048b5d in main () at main.cc:25
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: dead-lock in ReadPDFImage, no Exception can be caught

Post by magick »

ReadImage() calls ReadPDFImage() which in turn calls ReadImage() again causing the dead-lock. We've never seen this problem before. Are you using a recent release of ImageMagick? The current release is 6.4.5-5. Post your command line so we can try to reproduce the problem. Does the problem occur for all PDF's or a particular PDF? If its a particular PDF, post a URL here so we can download it and reproduce the problem.
Akechi

Re: dead-lock in ReadPDFImage, no Exception can be caught

Post by Akechi »

Yes, I'm using the newest release. It may be no problem in previous versions before 6.4.4.

The image is:
http://tw.pic.bysources.com/newsinfo/min/1251a.jpg

//My code:
#include <Magick++.h>
#include <string>
#include<stdio.h>
using namespace std;
using namespace Magick;

int main(){
FILE * fp;
fp = fopen("1251a.jpg", "r");
if(fp==NULL)
{
return 0;
}
char *test = new char[6000000];
fread(test, sizeof(char), nnum, fp);

Blob blob(test, sizeof(char)*nnum);
Image image;
try
{
image.read( blob );
}
catch( Exception &error_ )
{
printf("Caught exception:%s\n", error_.what());
return EXIT_FAILURE;
}
delete test;
fclose(fp);
return EXIT_SUCCESS;
}
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: dead-lock in ReadPDFImage, no Exception can be caught

Post by magick »

Your JPEG image is actually a PDF and one that cannot be rendered (see below). Can you try ImageMagick-6.4.5-6 Beta available in ftp://ftp.imagemagick.org/pub/ImageMagick/beta? We tested with that version of your program returned with:
  • [madison@magick demos]# magick++
    Error: /undefinedresource in findresource
    Operand stack:
    --dict:5/14(L)-- F1 11.25 --dict:6/6(L)-- --dict:6/6(L)-- ¼Ð·¢Åé --dict:9/12(ro)(G)-- --nostringval-- --dict:8/8(L)-- --dict:8/8(L)-- Adobe-CNS1 CIDFont Adobe-CNS1
    Execution stack:
    %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1889 1 3 %oparray_pop 1888 1 3 %oparray_pop 1872 1 3 %oparray_pop --nostringval-- --nostringval-- 2 1 2 --nostringval-- %for_pos_int_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval-- false 1 %stopped_push --nostringval-- %loop_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- %loop_continue --nostringval-- 1840 12 9 %oparray_pop findresource %errorexec_pop --nostringval-- --nostringval-- --nostringval--
    Dictionary stack:
    --dict:1150/1684(ro)(G)-- --dict:2/20(G)-- --dict:75/200(L)-- --dict:75/200(L)-- --dict:106/127(ro)(G)-- --dict:274/300(ro)(G)-- --dict:21/25(L)-- --dict:4/6(L)-- --dict:24/31(L)-- --dict:20/26(ro)(G)--
    Current allocation mode is local
    Last OS error: 2
    GPL Ghostscript 8.60: Unrecoverable error, exit code 1
    Caught exception:ImageMagick: Postscript delegate failed `/tmp/magick-XX7rVd3K': No such file or directory @ coders/pdf.c/ReadPDFImage/593
Akechi

Re: dead-lock in ReadPDFImage, no Exception can be caught

Post by Akechi »

I tried the version ImageMagick-6.4.5-6 Beta, no Exception yet, just as before...
Are you using the very 'image' of http://tw.pic.bysources.com/newsinfo/min/1251a.jpg with my posted code?

//Here's my corrected code(add a missing line):
// main.cc
#include <Magick++.h>
#include <string>
#include<stdio.h>
#define nnum 6000000// this line added.
using namespace std;
using namespace Magick;

int main(){
FILE * fp;
fp = fopen("1251a.jpg", "r");
if(fp==NULL)
{
return 0;
}
char *test = new char[nnum];
fread(test, sizeof(char), nnum, fp);

Blob blob(test, sizeof(char)*nnum);
Image image;
try
{
image.read( blob );
}
catch( Exception &error_ )
{
printf("Caught exception:%s\n", error_.what());
return EXIT_FAILURE;
}
delete test;
fclose(fp);
return EXIT_SUCCESS;
}


[]$ g++ -o t_magic main.cc `Magick++-config --cppflags --cxxflags --ldflags --libs`
[]$ ./t_magic &
[1] 1882
[]$
**** This file has a corrupted %%EOF marker, or garbage after the %%EOF.
Error: /rangecheck in --readline--
Operand stack:
5995900 5995900 () (\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000...) 5995643 --nostringval-- (\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000...)
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1 3 %oparray_pop 1 3 %oparray_pop 1 3 %oparray_pop --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- %loop_continue --nostringval-- --nostringval-- --nostringval--
Dictionary stack:
--dict:1069/1123(ro)(G)-- --dict:0/20(G)-- --dict:93/200(L)-- --dict:93/200(L)-- --dict:97/127(ro)(G)-- --dict:229/230(ro)(G)-- --dict:10/15(L)--
Current allocation mode is local
GNU Ghostscript 7.07: Unrecoverable error, exit code 1

[]$ gdb -p 1882
(gdb) bt
#0 0x00636402 in ?? ()
#1 0x0053913e in __lll_mutex_lock_wait () from /lib/tls/libpthread.so.0
#2 0x00535d9b in _L_mutex_lock_35 () from /lib/tls/libpthread.so.0
#3 0xbfeffc78 in ?? ()
#4 0x002b9d94 in ?? () from /usr/local/lib/libMagickCore.so.1
#5 0x00303cb0 in instantiate_configure () from /usr/local/lib/libMagickCore.so.1
#6 0x08962cc8 in ?? ()
#7 0xbfeffc88 in ?? ()
#8 0x00234e49 in LockSemaphoreInfo (semaphore_info=0x75a) at magick/semaphore.c:361
#9 0x00234e49 in LockSemaphoreInfo (semaphore_info=0x8962cc8) at magick/semaphore.c:361
#10 0x00234f4e in AcquireSemaphoreInfo (semaphore_info=0x303cb0) at magick/semaphore.c:147
#11 0x0016773b in ReadImage (image_info=0x89aa858, exception=0xbff11050) at magick/constitute.c:515
#12 0x00f1ea29 in ReadPDFImage (image_info=0x8967d88, exception=0xbff11050) at coders/pdf.c:585
#13 0x00167148 in ReadImage (image_info=0x8963c80, exception=0xbff11050) at magick/constitute.c:516
#14 0x0013d091 in BlobToImage (image_info=0x89391b0, blob=0xb738e008, length=6000000, exception=0xbff11050) at magick/blob.c:376
#15 0x00719a72 in Magick::Image::read (this=0xbff110b0, blob_=@0xbff110c0) at Magick++/lib/Image.cpp:1578
#16 0x080489ba in main () at main.cc:22
(gdb) q
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: dead-lock in ReadPDFImage, no Exception can be caught

Post by magick »

We added a patch to ensure the intermediate rendered PDF exists before it is read. This may fix the problem you reported. Look for an update to ImageMagick-6.4.5-6 sometime tomorrow.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: dead-lock in ReadPDFImage, no Exception can be caught

Post by magick »

Does this work:
  • convert logo: logo.pdf
    convert logo.pdf logo.pam
If so, its possible your PDF cannot be processed by ImageMagick. If these commands fail, most likely you do not have Ghostscript installed or its not in your execution path.
Akechi

Re: dead-lock in ReadPDFImage, no Exception can be caught

Post by Akechi »

6.4.5-8 works.
Many thanks!
Post Reply