crash while freeing memory

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
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

crash while freeing memory

Post by imaggie »

Hi,

I have been using ceptstrum script from http://www.fmwconcepts.com/imagemagick/

It usually works but some images cause imagemagick to dump out:

Code: Select all

...
Region: 46 out of 49
Region: 47 out of 49
Region: 48 out of 49
Region: 49 out of 49

*** glibc detected *** convert: free(): invalid next size (normal): 0x081079e8 ***
======= Backtrace: =========
/lib/libc.so.6(+0x7239f)[0xb725739f]
/usr/lib/libMagickCore.so.5(RelinquishMagickMemory+0x20)[0xb75af2e0]
======= Memory map: ========
08048000-08049000 r-xp 00000000 03:0b 2025445    /usr/bin/convert
08049000-0804a000 r--p 00000000 03:0b 2025445    /usr/bin/convert
0804a000-0804b000 rw-p 00001000 03:0b 2025445    /usr/bin/convert
0804b000-08117000 rw-p 00000000 00:00 0          [heap]
b6cdd000-b6cdf000 rw-p 00000000 00:00 0 
b6cdf000-b6ce4000 r-xp 00000000 03:0b 1825632    /usr/lib/libXdmcp.so.6.0.0
b6ce4000-b6ce5000 r--p 00004000 03:0b 1825632    /usr/lib/libXdmcp.so.6.0.0
b6ce5000-b6ce6000 rw-p 00005000 03:0b 1825632    /usr/lib/libXdmcp.so.6.0.0
b6ce6000-b6ce8000 r-xp 00000000 03:0b 1799390    /usr/lib/libXau.so.6.0.0
b6ce8000-b6ce9000 r--p 00001000 03:0b 1799390    /usr/lib/libXau.so.6.0.0
b6ce9000-b6cea000 rw-p 00002000 03:0b 1799390    /usr/lib/libXau.so.6.0.0
b6cea000-b6d09000 r-xp 00000000 03:0b 1756298    /usr/lib/libxcb.so.1.1.0
b6d09000-b6d0a000 r--p 0001e000 03:0b 1756298    /usr/lib/libxcb.so.1.1.0
b6d0a000-b6d0b000 rw-p 0001f000 03:0b 1756298    /usr/lib/libxcb.so.1.1.0
b6d0b000-b6d0c000 rw-p 00000000 00:00 0 
b6d0c000-b6d10000 r-xp 00000000 03:0b 1890473    /lib/libuuid.so.1.3.0
b6d10000-b6d11000 r--p 00003000 03:0b 1890473    /lib/libuuid.so.1.3.0
b6d11000-b6d12000 rw-p 00004000 03:0b 1890473    /lib/libuuid.so.1.3.0
b6d12000-b6d3b000 r-xp 00000000 03:0b 1756810    /usr/lib/libexpat.so.1.6.0
b6d3b000-b6d3d000 r--p 00028000 03:0b 1756810    /usr/lib/libexpat.so.1.6.0
b6d3d000-b6d3e000 rw-p 0002a000 03:0b 1756810    /usr/lib/libexpat.so.1.6.0
b6d3e000-b6d40000 r-xp 00000000 03:0b 1753132    /lib/libdl-2.15.so
b6d40000-b6d41000 r--p 00001000 03:0b 1753132    /lib/libdl-2.15.so
b6d41000-b6d42000 rw-p 00002000 03:0b 1753132    /lib/libdl-2.15.so
b6d42000-b6d4a000 r-xp 00000000 03:0b 1225094    /usr/lib/libltdl.so.7.3.0
b6d4a000-b6d4b000 r--p 00007000 03:0b 1225094    /usr/lib/libltdl.so.7.3.0
b6d4b000-b6d4c000 rw-p 00008000 03:0b 1225094    /usr/lib/libltdl.so.7.3.0
b6d4c000-b6d71000 r-xp 00000000 03:0b 1753133    /lib/libm-2.15.so
b6d71000-b6d72000 r--p 00024000 03:0b 1753133    /lib/libm-2.15.so
b6d72000-b6d73000 rw-p 00025000 03:0b 1753133    /lib/libm-2.15.so
b6d73000-b6d74000 rw-p 00000000 00:00 0 
b6d74000-b6d88000 r-xp 00000000 03:0b 1798922    /lib/libz.so.1.2.7
b6d88000-b6d89000 r--p 00013000 03:0b 1798922    /lib/libz.so.1.2.7
b6d89000-b6d8a000 rw-p 00014000 03:0b 1798922    /lib/libz.so.1.2.7
b6d8a000-b6d99000 r-xp 00000000 03:0b 801725     /lib/libbz2.so.1.0.6
b6d99000-b6d9a000 r--p 0000e000 03:0b 801725     /lib/libbz2.so.1.0.6
b6d9a000-b6d9b000 rw-p 0000f000 03:0b 801725     /lib/libbz2.so.1.0.6
b6d9b000-b6def000 r-xp 00000000 03:0b 1826221    /usr/lib/libXt.so.6.0.0
b6def000-b6df0000 r--p 00053000 03:0b 1826221    /usr/lib/libXt.so.6.0.0
b6df0000-b6df3000 rw-p 00054000 03:0b 1826221    /usr/lib/libXt.so.6.0.0
b6df3000-b6f1a000 r-xp 00000000 03:0b 1794708    /usr/lib/libX11.so.6.3.0
b6f1a000-b6f1b000 r--p 00127000 03:0b 1794708    /usr/lib/libX11.so.6.3.0
b6f1b000-b6f1e000 rw-p 00128000 03:0b 1794708    /usr/lib/libX11.so.6.3.0
b6f1e000-b6f33000 r-xp 00000000 03:0b 1794775    /usr/lib/libICE.so.6.3.0
b6f33000-b6f34000 r--p 00014000 03:0b 1794775    /usr/lib/libICE.so.6.3.0
b6f34000-b6f35000 rw-p 00015000 03:0b 1794775    /usr/lib/libICE.so.6.3.0
b6f35000-b6f37000 rw-p 00000000 00:00 0 
b6f37000-b6f3e000 r-xp 00000000 03:0b 1825841    /usr/lib/libSM.so.6.0.1
b6f3e000-b6f3f000 r--p 00006000 03:0b 1825841    /usr/lib/libSM.so.6.0.1
b6f3f000-b6f40000 rw-p 00007000 03:0b 1825841    /usr/lib/libSM.so.6.0.1
b6f40000-b6f4f000 r-xp 00000000 03:0b 1794909    /usr/lib/libXext.so.6.4.0
b6f4f000-b6f50000 r--p 0000e000 03:0b 1794909    /usr/lib/libXext.so.6.4.0
b6f50000-b6f51000 rw-p 0000f000 03:0b 1794909    /usr/lib/libXext.so.6.4.0
b6f51000-b6f52000 rw-p 00000000 00:00 0 
b6f52000-b6f83000 r-xp 00000000 03:0b 1796038    /usr/lib/libfontconfig.so.1.5.0
b6f83000-b6f84000 r--p 00031000 03:0b 1796038    /usr/lib/libfontconfig.so.1.5.0
b6f84000-b6f85000 rw-p 00032000 03:0b 1796038    /usr/lib/libfontconfig.so.1.5.0
b6f85000-b7057000 r-xp 00000000 03:0b 1821488    /usr/lib/libfftw3.so.3.3.2
b7057000-b705c000 r--p 000d2000 03:0b 1821488    /usr/lib/libfftw3.so.3.3.2
b705c000-b705d000 rw-p 000d7000 03:0b 1821488    /usr/lib/libfftw3.so.3.3.2
b705d000-b7091000 r-xp 00000000 03:0b 1657582    /usr/lib/libjpeg.so.8.4.0
b7091000-b7092000 ---p 00034000 03:0b 1657582    /usr/lib/libjpeg.so.8.4.0
b7092000-b7093000 r--p 00034000 03:0b 1657582    /usr/lib/libjpeg.so.8.4.0
b7093000-b7094000 rw-p 00035000 03:0b 1657582    /usr/lib/libjpeg.so.8.4.0
b7094000-b7124000 r-xp 00000000 03:0b 2071658    /usr/lib/libfreetype.so.6.9.0
b7124000-b7128000 r--p 0008f000 03:0b 2071658    /usr/lib/libfreetype.so.6.9.0
b7128000-b7129000 rw-p 00093000 03:0b 2071658    /usr/lib/libfreetype.so.6.9.0
b7129000-b7195000 r-xp 00000000 03:0b 2069835    /usr/lib/libtiff.so.5.1.0
b7195000-b7196000 r--p 0006b000 03:0b 2069835    /usr/lib/libtiff.so.5.1.0
b7196000-b7198000 rw-p 0006c000 03:0b 2069835    /usr/lib/libtiff.so.5.1.0
b7198000-b719a000 rw-p 00000000 00:00 0 
b719a000-b71df000 r-xp 00000000 03:0b 1669684    /usr/lib/liblcms2.so.2.0.3
b71df000-b71e0000 ---p 00045000 03:0b 1669684    /usr/lib/liblcms2.so.2.0.3
b71e0000-b71e1000 r--p 00045000 03:0b 1669684    /usr/lib/liblcms2.so.2.0.3
b71e1000-b71e4000 rw-p 00046000 03:0b 1669684    /usr/lib/liblcms2.so.2.0.3
b71e4000-b71e5000 rw-p 00000000 00:00 0 
b71e5000-b7365000 r-xp 00000000 03:0b 1753109    /lib/libc-2.15.so
b7365000-b7367000 r--p 00180000 03:0b 1753109    /lib/libc-2.15.so
b7367000-b7368000 rw-p 00182000 03:0b 1753109    /lib/libc-2.15.so
b7368000-b736b000 rw-p 00000000 00:00 0 
b736b000-b7381000 r-xp 00000000 03:0b 1753115    /lib/libpthread-2.15.so
b7381000-b7382000 r--p 00015000 03:0b 1753115    /lib/libpthread-2.15.so
b7382000-b7383000 rw-p 00016000 03:0b 1753115    /lib/libpthread-2.15.so
b7383000-b7385000 rw-p 00000000 00:00 0 
b7385000-b749d000 r-xp 00000000 03:0b 2026605    /usr/lib/libMagickWand.so.5.0.0
b749d000-b749e000 r--p 00118000 03:0b 2026605    /usr/lib/libMagickWand.so.5.0.0
b749e000-b74a0000 rw-p 00119000 03:0b 2026605    /usr/lib/libMagickWand.so.5.0.0
b74a0000-b76a2000 r-xp 00000000 03:0b 2026606    /usr/lib/libMagickCore.so.5.0.0
b76a2000-b76a3000 ---p 00202000 03:0b 2026606    /usr/lib/libMagickCore.so.5.0.0
b76a3000-b76ad000 r--p 00202000 03:0b 2026606    /usr/lib/libMagickCore.so.5.0.0
b76ad000-b76f3000 rw-p 0020c000 03:0b 2026606    /usr/lib/libMagickCore.so.5.0.0
b76f3000-b770b000 rw-p 00000000 00:00 0 
b7712000-b772d000 r-xp 00000000 03:0b 806378     /usr/lib/gcc/i686-pc-linux-gnu/4.5.2/libgcc_s.so.1
b772d000-b772e000 r--p 0001a000 03:0b 806378     /usr/lib/gcc/i686-pc-linux-gnu/4.5.2/libgcc_s.so.1
b772e000-b772f000 rw-p 0001b000 03:0b 806378     /usr/lib/gcc/i686-pc-linux-gnu/4.5.2/libgcc_s.so.1
b772f000-b7730000 rw-p 00000000 00:00 0 
b7730000-b7731000 r-xp 00000000 03:0b 2026634    /usr/lib/ImageMagick-6.7.7/modules-Q32/coders/xc.so
b7731000-b7732000 r--p 00001000 03:0b 2026634    /usr/lib/ImageMagick-6.7.7/modules-Q32/coders/xc.so
b7732000-b7733000 rw-p 00002000 03:0b 2026634    /usr/lib/ImageMagick-6.7.7/modules-Q32/coders/xc.so
b7733000-b773c000 r-xp 00000000 03:0b 2026685    /usr/lib/ImageMagick-6.7.7/modules-Q32/coders/pnm.so
b773c000-b773d000 r--p 00009000 03:0b 2026685    /usr/lib/ImageMagick-6.7.7/modules-Q32/coders/pnm.so
b773d000-b773e000 rw-p 0000a000 03:0b 2026685    /usr/lib/ImageMagick-6.7.7/modules-Q32/coders/pnm.so
b773e000-b773f000 rw-p 00000000 00:00 0 
b773f000-b775d000 r-xp 00000000 03:0b 1753111    /lib/ld-2.15.so
b775d000-b775e000 r--p 0001d000 03:0b 1753111    /lib/ld-2.15.so
b775e000-b775f000 rw-p 0001e000 03:0b 1753111    /lib/ld-2.15.so
bfa98000-bfab3000 rw-p 00000000 00:00 0          [stack]
ffffe000-fffff000 r-xp 00000000 00:00 0          [vdso]
./cepstrum: line 345:  6909 Aborted                 convert $tmp1 $mult1 -evaluate log $constant -negate $mult2 \( -size ${sw}x${sh} xc:black \) +ift -roll -${swr}-${shr} $outfile


 $ file $base.png
cygale-nez.png: PNG image data, 300 x 300, 8-bit/color RGBA, non-interlaced
Since it is failing during freeing memory it looks like it is imagemagick that is failing rather than anything to do with the script.

Code: Select all

 $ convert -version
Version: ImageMagick 6.7.7-5 2012-07-02 Q32 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features:   HDRI  
I have seen this quite a lot in the past but not managed to see why some images fail and others seem OK.

Any suggestions?

TIA.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: crash while freeing memory

Post by fmw42 »

Can you provide a link to your image or send it to me separately (fmw at alink dot net). I will test it out and see if it fails for me.

Fred
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

Re: crash while freeing memory

Post by imaggie »

irrespective of what Fred's script is doing, there seems to be an attempt to free something that has already been freed or not malloced in the first place.

This should be fixed.
Here is the image in question.

http://i47.tinypic.com/j76fli.png
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

Re: crash while freeing memory

Post by imaggie »

Here is a pfm generated by cepstrum script that causes the crash

http://piments.com/tmp/fftcepstrum_1_30628.pfm

Code: Select all

convert ./fftcepstrum_1_30628.pfm    \( -size  75x75 xc:black \) +ift   $outfile
Now whatever the script has put into that file I would suggest IM should handle it better than the crash. This does not happen with all images so this suggests insufficient error trapping in ift probably during RelinquishMagickMemory

regards.
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

Re: crash while freeing memory

Post by imaggie »

A similar snip from the same source image gets processed without problems.

Code: Select all

 ./cepstrum -G cygale-eye.png cygale-eye_cep.gif
...
Region: 47 out of 49
Region: 48 out of 49
Region: 49 out of 49

variable dump before last operation:\n 10000 ./fftcepstrum_1_31215.pfm 10000 117x117 -58-58 cygale-eye_cep.gif

Code: Select all

file cygale-eye.png cygale-eye_cep.gif
cygale-eye.png:     PNG image data, 470 x 470, 8-bit/color RGBA, non-interlaced
cygale-eye_cep.gif: GIF image data, version 89a, 117 x 117
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: crash while freeing memory

Post by magick »

We can reproduce the problem you posted and have a patch. Look for it in ImageMagick 6.7.8-2 Beta by sometime tomorrow. Thanks.
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

Re: crash while freeing memory

Post by imaggie »

Hey fast work. Thanks.

Glad I was able to help you locate the problem.
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

Re: crash while freeing memory

Post by imaggie »

BTW where are download instructions for beta ? I'm running for lastest distro tarballs now.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: crash while freeing memory

Post by fmw42 »

imaggie wrote:BTW where are download instructions for beta ? I'm running for lastest distro tarballs now.
Beta's are available from http://magick.imagemagick.org/download/beta/
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

Re: crash while freeing memory

Post by imaggie »

Just built the new beta and it now behaves as expected.

Thanks for the quick bugfix.
:D
Post Reply