program crash on catched coder warning exception (IM 6.3.7)

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
nicolas1

program crash on catched coder warning exception (IM 6.3.7)

Post by nicolas1 »

Hello,

I have problem that program crashed on coder warning exception raised:
what: Coder Warning: Corrupt JPEG data: 1027 extraneous bytes before marker 0xd9

Program crashed only one time, but other times program did not get crashed...

Can you provide any hint on this situation? How to make program more stable on such exceptions?

Thanks
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: program crash on catched coder warning exception (IM 6.3.7)

Post by anthony »

Report a bug with a link to a copy of the image. IM should NOT crash, ever. Give warnings and errors yes, crash no.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
nicolas1

Re: program crash on catched coder warning exception (IM 6.3.7)

Post by nicolas1 »

what is expected behavior for IM when Magick::WarningCorruptImage catched ?
As I see "DestroyImageList" function fails (pointer is zero). What happens with resources which were taken by corrupted image?

Also IM crash when attempt to delete corrupted file object. So, resources are not freed...

Btw, how can I post sample image files?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: program crash on catched coder warning exception (IM 6.3.7)

Post by anthony »

DestroyImageList() will always return a NULL pointer. You use it to assign it back to the image list pointer so you know it is invalid!

Code: Select all

list = DestroyImageList(list)

You put your image up somewhere on the web (anywhere) am post a link to that image.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: program crash on catched coder warning exception (IM 6.3.7)

Post by anthony »

Unable to download the images... The download site does not like my multi-host proxy server as a later request can some from a slightly different IP than the previous request!

Can you please start a new topic in BUGS with the original problem and the links to the files.

thank you.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: program crash on catched coder warning exception (IM 6.3.7)

Post by magick »

To fix this problem we need a small program we can download to reproduce the problem or a stack trace. We tried converting your DSCF040.JPG image about one hundred times with the latest ImageMagick release, 6.4.3-6, and each time it threw the 'corrupt jpeg data' exception but still exited without crashing.
nicolas1

Re: program crash on catched coder warning exception (IM 6.3.7)

Post by nicolas1 »

The problem is memory leak. When c++ exception caught, destroying of Magick::Image object causes program crash. In stack trace it is DestroyImageList(NULL) , while on other magick warnings destroying of Magick::Image object does not make program crash, DestroyImageList(!NULL).

Code: Select all


shared_ptr<Magick::Image> magick_image(new Magick::Image());

 try
{
   magick_image->read(filename_);
}
catch( Magick::WarningCoder &warning )
{
  // this exception is OK.
}
catch (Magick::WarningCorruptImage &warning)
{
  // this causes crash once magick_image becomes out of scope
}

User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: program crash on catched coder warning exception (IM 6.3.7)

Post by magick »

See http://www.imagemagick.org/Magick++/Exception.html. Your program runs fine if you wrap your code with another try:

Code: Select all

try
{
  try
  {
     magick_image->read(filename_);
  }
  catch( Magick::WarningCoder &warning )
  {
    // this exception is OK.
  }
  catch (Magick::WarningCorruptImage &warning)
  {
    // this causes crash once magick_image becomes out of scope
  }
}
catch( std::exception &error ) 
{ 
   // Process any other exceptions derived from standard C++ exception
   err << “Caught C++ STD exception: “ << error.what() << endl;
} 
catch( ... ) 
{ 
  // Process *any* exception (last-ditch effort). There is not a lot
  // you can do here other to retry the operation that failed, or exit
  // the program. 
}
nicolas1

Re: program crash on catched coder warning exception (IM 6.3.7)

Post by nicolas1 »

Yes, resolved. Thanks. Problem was pointer imageInfo()->size was not NULL befor Magick::Image object destruction. Btw, how memory for imageInfo()->size string must be allocated? (Because it seems that IM tries to free it).
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: program crash on catched coder warning exception (IM 6.3.7)

Post by magick »

Structured string members, in most cases, should be allocated from the heap:
  • image_info->size = ConstantString("50x50+0+0");
Post Reply