Crash with "Assertion failed: (semaphore_info..."

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
n1k

Crash with "Assertion failed: (semaphore_info..."

Post by n1k »

Hello,
use Magick++ in 10 threads

Code: Select all

        Magick::Image master;
        try
        {
            master.read(path_source + image_filename);
            float ratio = (float)master.baseColumns()/master.baseRows();
            if(ratio >= 1.19 && ratio <= 1.46)
            {
                //nothing
            }
            else
            if(ratio > 1.46 && ratio < 1.6)
            {
                master.crop(Magick::Geometry((int)master.baseColumns()*0.9, master.baseRows(), (int)master.baseColumns()*0.05, 0));
                LOG::log_file->WriteLog(LOG::INFO, "%s", ("Image " + image_filename + " cropped").c_str());
            }
            else
            if(ratio > 1.07 && ratio < 1.19)
            {
                master.crop(Magick::Geometry(master.baseColumns(), (int)master.baseRows()*0.9, 0, (int)master.baseRows()*0.05));
            }
            else
            {
                return 1;
            }
            for(uint i = 0; i < m_config.img_size.size(); i++)
            {
                Magick::Image image_tmp = master;
                image_tmp.resize(m_config.img_size[i].size);
                image_tmp.magick("JPEG");
                std::string path_res = m_config.Media_storage;
                path_res += m_config.img_size[i].name + "/" + image_filename.substr(0,1) + "/" + image_filename.substr(1,2) + "/";
                if (! boost::filesystem::exists(path_res))
                {
                    boost::filesystem::create_directories(path_res);
                }
                image_tmp.write(path_res + image_filename + ".jpg");
            }
        }
        catch( Magick::Exception &error )
        {
            LOG::log_file->WriteLog(LOG::ERROR, error.what());
            return 1;
        }
        catch( std::exception &error)
        {
            LOG::log_file->WriteLog(LOG::ERROR, error.what());
            return 1;
        }
And Magic++ crash with message in stderr " Assertion failed: (semaphore_info != (SemaphoreInfo *) NULL), function LockSemaphoreInfo, file magick/semaphore.c, line 288"

Gdb bugtrace:

Code: Select all

(gdb) bt
#0  0x0000000802a12a9c in thr_kill () from /lib/libc.so.7
#1  0x0000000802aa1ffb in abort () from /lib/libc.so.7
#2  0x0000000802a89fc5 in __assert () from /lib/libc.so.7
#3  0x000000080185a56d in LockSemaphoreInfo () from /usr/local/lib/libMagickCore.so.2
#4  0x00000008017e5650 in DestroyExceptionInfo () from /usr/local/lib/libMagickCore.so.2
#5  0x0000000801801c5a in DestroyImage () from /usr/local/lib/libMagickCore.so.2
#6  0x000000080180c658 in DestroyImageList () from /usr/local/lib/libMagickCore.so.2
#7  0x0000000801e50035 in Magick::ImageRef::~ImageRef () from /usr/local/lib/libMagick++.so.2
#8  0x0000000801e495a9 in Magick::Image::~Image () from /usr/local/lib/libMagick++.so.2
#9  0x0000000000423012 in UpdaterSlave::ResizeImage (this=0x806e17000, image_filename=Variable "image_filename" is not available.
) at HarvesterSlave.cpp:944
#10 0x0000000000424f7b in UpdaterSlave::GetPropPhoto (this=0x806e17000, hex_name=@0x7fffff9fdd30, html=Variable "html" is not available.
) at HarvesterSlave.cpp:1623
#11 0x00000000004323d6 in UpdaterSlave::harvest_thread (US=Variable "US" is not available.
) at HarvesterSlave.cpp:1113
#12 0x00000008014554d1 in pthread_getprio () from /lib/libthr.so.3
#13 0x0000000000000000 in ?? ()
Cannot access memory at address 0x7fffff9fe000
compile Magick++ with option "OpenMP"

What should I do? How to solve this problem? :(
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Crash with "Assertion failed: (semaphore_info..."

Post by magick »

We'll need a complete working program in order to download it and reproduce the problem. We tried a slimmed down version of your code with ImageMagick 6.6.0-5 and it worked without complaint. ImageMagick does support threads of execution so your code should work.
n1k

Re: Crash with "Assertion failed: (semaphore_info..."

Post by n1k »

Forgot to say that the version ImageMagick is 6.5.8.1. This version lastest for FreeBSD ports.
n1k

Re: Crash with "Assertion failed: (semaphore_info..."

Post by n1k »

Good day,
I found the cause of falls. If read this image http://media.wiweb.ru/data/images/_base ... -92873.jpg (there are other bad pictures).

I save bad image to 0.jpg.

In FreeBSD with ImageMagick 6.5.8-1 with try...catch

Code: Select all

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <Magick++.h>

using namespace std;
int
main(void)
{
    try
        {
           Magick::Image master;
           master.read("0.jpg");
        }
        catch( Magick::Exception &error )
        {
            fprintf(stderr, "I exit  %s\n", error.what());
            return NULL;
        }
        catch( std::exception &error)
        {
            fprintf(stderr, "I exit %s\n", error.what());
            return NULL;
        }
   return 0;
}
This code return "Assertion failed: (semaphore_info != (SemaphoreInfo *) NULL), function LockSemaphoreInfo, file magick/semaphore.c, line 288." and Aboart.

In FreeBSD with ImageMagick 6.5.8-1without try...catch

Code: Select all

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <Magick++.h>

using namespace std;
int
main(void)
{
           Magick::Image master;
           master.read("0.jpg");
   return 0;
}
This code return "what(): Magick: Corrupt JPEG data: premature end of data segment `0.jpg' @ jpeg.c/EmitMessage/228" and Aboart.


In Ubuntu with ImageMagick 6.5.1-0 with try...catch

Code: Select all

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <Magick++.h>

using namespace std;
int
main(void)
{
    try
        {
           Magick::Image master;
           master.read("0.jpg");
        }
        catch( Magick::Exception &error )
        {
            fprintf(stderr, "I exit  %s\n", error.what());
            return NULL;
        }
        catch( std::exception &error)
        {
            fprintf(stderr, "I exit %s\n", error.what());
            return NULL;
        }
   return 0;
}
This code return "I exit what(): Magick: Corrupt JPEG data: premature end of data segment `0.jpg' @ jpeg.c/EmitMessage/227" and Segmentation fault.

In Ubuntu with ImageMagick 6.5.1-0 without try...catch

Code: Select all

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <Magick++.h>

using namespace std;
int
main(void)
{
           Magick::Image master;
           master.read("0.jpg");
   return 0;
}
This code return "what(): Magick: Corrupt JPEG data: premature end of data segment `0.jpg' @ jpeg.c/EmitMessage/227" and Aboart.

PS. I use latest version Magik++ for OS in ports or synaptic.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Crash with "Assertion failed: (semaphore_info..."

Post by magick »

We're not sure why its failing on FreeBSD. We tried your code / image under Fedora and Redhat and it returned the corrupt image exception as expected. If you have the ImageMagick development RPM installed on FreeBSD, you can compile the latest ImageMagick release from source to see if that fixes the problem. The development release installs all the dependencies and the header files that ImageMagick relies on (e.g. JPEG, PNG, etc). Download the source, unpack, and type
  • cd ImageMagick-6.6.0
    ./configure
    make
    make install
now compile your Magick++ code and verify it returns an exception as expected.
n1k

Re: Crash with "Assertion failed: (semaphore_info..."

Post by n1k »

Thank you very much. Installed version 6.6.0-5. Handling bad image is correct.
Post Reply