php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59752 Segmentation fault after execution of php script wich uses imagick
Submitted: 2011-05-05 12:52 UTC Modified: 2015-01-08 22:27 UTC
Votes:3
Avg. Score:4.3 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:0 (0.0%)
From: luminarior at gmail dot com Assigned: mkoppanen (profile)
Status: Wont fix Package: imagick (PECL)
PHP Version: 5.3.6 OS: Gentoo Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-05-05 12:52 UTC] luminarior at gmail dot com
Description:
------------
(I selected PHP 5.3.5 version in your form because you don't have 5.3.6.)

I wrote a php script (See link below) wich uses imagick (PHP wrapper for the ImageMagick library) to draw some logos for my site. The script executes and draws images OK, but in the end it generates segfaults. I think that you have some problems in your garbage collector because this script doesn't generate segfault in the end in case you use just one cycle of "for" or just one function "draw()".

I tried to compile php and imagick in debug mode and generate you some backtrace in gdb (see below):

#CFLAGS="-ggdb3" CXXFLAGS="${CFLAGS}" LDFLAGS="-Wl,-O1 -Wl,--as-needed" FEATURES="nostrip" USE="debug" emerge -1 dev-lang/php

These are the packages that would be merged, in reverse order:

Calculating dependencies... done!
[ebuild   R   ] dev-lang/php-5.3.6  USE="apache2 berkdb bzip2 cjk cli crypt ctype debug* exif fileinfo filter ftp gd gdbm hash iconv ipv6 json ldap mysql mysqli nls phar posix readline session simplexml spell ssl threads tokenizer truetype unicode xml zlib (-adabas) -bcmath (-birdstep) -calendar -cdb -cgi -curl -curlwrappers -db2 (-dbmaker) -doc -embed (-empress) (-empress-bcs) -enchant (-esoob) -firebird -flatfile -fpm (-frontbase) -gd-external -gmp -imap -inifile -interbase -intl -iodbc -kerberos -kolab -ldap-sasl -libedit -mhash -mssql -mysqlnd -oci8 -oci8-instant-client -odbc -pcntl -pdo -pic -postgres -qdbm -recode -sapdb -sharedext -sharedmem -snmp -soap -sockets (-solid) -sqlite -sqlite3 (-sybase-ct) -sysvipc -tidy -wddx -xmlreader -xmlrpc -xmlwriter -xpm -xsl -zip" 0 kB 

# CFLAGS="-ggdb3" CXXFLAGS="${CFLAGS}" LDFLAGS="-Wl,-O1 -Wl,--as-needed" FEATURES="nostrip" USE="debug" emerge -1 dev-php5/pecl-imagick

These are the packages that would be merged, in reverse order:

Calculating dependencies... done!
[ebuild   R   ] dev-php5/pecl-imagick-3.0.1-r1  USE="-examples" PHP_TARGETS="php5-3 -php5-2" 0 kB

Total: 1 package (1 reinstall), Size of downloads: 0 kB

I have the following system:
# uname -a
Linux ddd 2.6.37-gentoo-r4 #2 SMP Fri Apr 29 20:19:52 MSD 2011 x86_64 AMD Phenom(tm) II X3 710 Processor AuthenticAMD GNU/Linux

Reproduce code:
---------------
This is my PHP script:
http://pastebin.com/x67mn6NL

Expected result:
----------------
Without segfaults in the end.

Actual result:
--------------
# gdb /usr/bin/php
GNU gdb (Gentoo 7.2 p1) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.gentoo.org/>...
Reading symbols from /usr/bin/php...done.
(gdb) set args /var/www/myhost/htdocs/imr/update-test.php
(gdb) r
Starting program: /usr/bin/php /var/www/myhost/htdocs/imr/update-test.php
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
[New LWP 7617]
[LWP 7617 exited]
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
[Thu May  5 19:37:06 2011]  Script:  '/var/www/myhost/htdocs/imr/update-test.php'
/var/tmp/portage/dev-lang/php-5.3.6/work/sapis-build/cli/Zend/zend_vm_execute.h(475) :  Freeing 0x012F2DD8 (32 bytes), script=/var/www/myhost/htdocs/imr/update-test.php
Last leak repeated 41 times
[Thu May  5 19:37:06 2011]  Script:  '/var/www/myhost/htdocs/imr/update-test.php'
/var/tmp/portage/dev-lang/php-5.3.6/work/sapis-build/cli/Zend/zend_vm_execute.h(300) :  Freeing 0x012F46A8 (32 bytes), script=/var/www/myhost/htdocs/imr/update-test.php
Last leak repeated 41 times
=== Total 84 memory leaks detected ===
[New LWP 7626]
[New LWP 7625]

Program received signal SIGSEGV, Segmentation fault.
[Switching to LWP 7625]
0x00007ffff70f1fda in ?? ()
(gdb) bt full
#0  0x00007ffff70f1fda in ?? ()
No symbol table info available.
#1  0x00007ffff70f0906 in ?? ()
No symbol table info available.
#2  0x0000000000000000 in ?? ()
No symbol table info available.
(gdb) q
A debugging session is active.

        Inferior 1 [process 7612] will be killed.

Quit anyway? (y or n) y

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-05-06 07:13 UTC] mkoppanen@php.net
Hi,

try compiling ImageMagick without OpenMP support and see if this helps
 [2011-05-06 12:22 UTC] luminarior at gmail dot com
(Your system doesn't like my password anymore)

After compiling ImageMagick without OpenMP support segfault doesn't occur. But it still sends a messages about detected memory leaks.
 [2011-05-06 12:26 UTC] luminarior at gmail dot com
("Login" link on your site doesn't work. Only "Password:" form works for me.)

I tried to do the following:
CFLAGS="-ggdb3" CXXFLAGS="${CFLAGS}" LDFLAGS="-Wl,-O1 -Wl,--as-needed" FEATURES="nostrip" USE="debug -openmp" emerge -1 media-gfx/imagemagick

After compilation I tried gdb again:
# gdb /usr/bin/php
GNU gdb (Gentoo 7.2 p1) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.gentoo.org/>...
Reading symbols from /usr/bin/php...done.
(gdb) set args /var/www/myhost/htdocs/imr/update-test.php
(gdb) r
Starting program: /usr/bin/php /var/www/myhost/htdocs/imr/update-test.php
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
[New LWP 26223]
[LWP 26223 exited]
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
[Fri May  6 19:22:19 2011]  Script:  '/var/www/myhost/htdocs/imr/update-test.php'
/var/tmp/portage/dev-lang/php-5.3.6/work/sapis-build/cli/Zend/zend_vm_execute.h(475) :  Freeing 0x016F7F18 (32 bytes), script=/var/www/myhost/htdocs/imr/update-test.php
Last leak repeated 41 times
[Fri May  6 19:22:19 2011]  Script:  '/var/www/myhost/htdocs/imr/update-test.php'
/var/tmp/portage/dev-lang/php-5.3.6/work/sapis-build/cli/Zend/zend_vm_execute.h(300) :  Freeing 0x016F97E8 (32 bytes), script=/var/www/myhost/htdocs/imr/update-test.php
Last leak repeated 41 times
=== Total 84 memory leaks detected ===

Program exited normally.
(gdb) bt full
No stack.
(gdb) q
 [2011-05-06 12:32 UTC] luminarior at gmail dot com
Then I tried to recompile imagemagick with openmp again:
CFLAGS="-ggdb3" CXXFLAGS="${CFLAGS}" LDFLAGS="-Wl,-O1 -Wl,--as-needed" FEATURES="nostrip" USE="debug" emerge -1 media-gfx/imagemagick

These are the packages that would be merged, in reverse order:

Calculating dependencies... done!
[ebuild   R   ] media-gfx/imagemagick-6.6.8.5  USE="X bzip2 corefonts cxx djvu jpeg jpeg2k lcms lzma openmp* perl png svg tiff truetype webp wmf xml zlib -autotrace -fftw -fontconfig -fpx -graphviz -gs -hdri -jbig -lqr -openexr -q32 -q8 -raw -static-libs" VIDEO_CARDS="nvidia" 0 kB 

Total: 1 package (1 reinstall), Size of downloads: 0 kB

It generates segfaults and doesn't give more useful debugging info unfortunatelly despite the fact that I tried to compile php, imagick and imagemagick with debug symbols:

# gdb /usr/bin/php
GNU gdb (Gentoo 7.2 p1) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.gentoo.org/>...
Reading symbols from /usr/bin/php...done.
(gdb) set args /var/www/myhost/htdocs/imr/update-test.php
(gdb) r
Starting program: /usr/bin/php /var/www/myhost/htdocs/imr/update-test.php
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
[New LWP 14755]
[LWP 14755 exited]
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
[Fri May  6 19:28:15 2011]  Script:  '/var/www/myhost/htdocs/imr/update-test.php'
/var/tmp/portage/dev-lang/php-5.3.6/work/sapis-build/cli/Zend/zend_vm_execute.h(475) :  Freeing 0x016F8DA8 (32 bytes), script=/var/www/myhost/htdocs/imr/update-test.php
Last leak repeated 41 times
[Fri May  6 19:28:15 2011]  Script:  '/var/www/myhost/htdocs/imr/update-test.php'
/var/tmp/portage/dev-lang/php-5.3.6/work/sapis-build/cli/Zend/zend_vm_execute.h(300) :  Freeing 0x016FA678 (32 bytes), script=/var/www/myhost/htdocs/imr/update-test.php
Last leak repeated 41 times
=== Total 84 memory leaks detected ===
[New LWP 14757]
[New LWP 14756]

Program received signal SIGSEGV, Segmentation fault.
[Switching to LWP 14756]
0x00007ffff5835fd8 in ?? ()
(gdb) bt full
#0  0x00007ffff5835fd8 in ?? ()
No symbol table info available.
#1  0x00007ffff5834906 in ?? ()
No symbol table info available.
#2  0x0000000000000000 in ?? ()
No symbol table info available.
(gdb) q
A debugging session is active.

        Inferior 1 [process 14752] will be killed.

Quit anyway? (y or n) y
 [2011-05-06 12:40 UTC] luminarior at gmail dot com
I generated also straces for you without (strace-openmp.log) and with (strace+openmp.log) OpenMP. You can download it from there:
http://www.filefactory.com/file/cb2e9a0/n/strace_tar_lzma
 [2011-05-06 12:55 UTC] mkoppanen@php.net
Can you run the script with:

USE_ZEND_ALLOC=0 valgrind php script.php
 [2011-05-06 13:13 UTC] luminarior at gmail dot com
# USE_ZEND_ALLOC=0 valgrind /usr/bin/php /var/www/myhost/htdocs/imr/update-test.php
==19633== Memcheck, a memory error detector
==19633== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==19633== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==19633== Command: /usr/bin/php /var/www/myhost/htdocs/imr/update-test.php
==19633== 

valgrind:  Fatal error at startup: a function redirection
valgrind:  which is mandatory for this platform-tool combination
valgrind:  cannot be set up.  Details of the redirection are:
valgrind:  
valgrind:  A must-be-redirected function
valgrind:  whose name matches the pattern:      strlen
valgrind:  in an object with soname matching:   ld-linux-x86-64.so.2
valgrind:  was not found whilst processing
valgrind:  symbols from the object with soname: ld-linux-x86-64.so.2
valgrind:  
valgrind:  Possible fixes: (1, short term): install glibc's debuginfo
valgrind:  package on this machine.  (2, longer term): ask the packagers
valgrind:  for your Linux distribution to please in future ship a non-
valgrind:  stripped ld.so (or whatever the dynamic linker .so is called)
valgrind:  that exports the above-named function using the standard
valgrind:  calling conventions for this platform.  The package you need
valgrind:  to install for fix (1) is called
valgrind:  
valgrind:    On Debian, Ubuntu:                 libc6-dbg
valgrind:    On SuSE, openSuSE, Fedora, RHEL:   glibc-debuginfo
valgrind:  
valgrind:  Cannot continue -- exiting now.  Sorry.
 [2011-05-06 15:03 UTC] mkoppanen@php.net
That's not very helpful output
 [2011-05-06 15:13 UTC] luminarior at gmail dot com
I tried to recompile glibc in debug mode:
# CFLAGS="-ggdb3" CXXFLAGS="${CFLAGS}" LDFLAGS="-Wl,-O1 -Wl,--as-needed" FEATURES="nostrip" USE="debug" emerge -1 glibc

These are the packages that would be merged, in reverse order:

Calculating dependencies... done!
[ebuild   R   ] sys-libs/glibc-2.11.3  USE="debug* glibc-omitfp (multilib) nls -gd (-hardened) -profile (-selinux) -vanilla" 0 kB

Total: 1 package (1 reinstall), Size of downloads: 0 kB

>>> Verifying ebuild manifests
>>> Emerging (1 of 1) sys-libs/glibc-2.11.3
>>> Installing (1 of 1) sys-libs/glibc-2.11.3
>>> Jobs: 1 of 1 complete                           Load avg: 2.03, 4.28, 5.65
>>> Auto-cleaning packages...

And Then I tried valgrind again. There's a log of
# USE_ZEND_ALLOC=0 valgrind /usr/bin/php /var/www/myhost/htdocs/imr/update-test.php

http://www.filefactory.com/file/cb2f107/n/valgrind_log_tar_lzma
 [2012-03-15 17:04 UTC] spam at ethaniel dot com
Try setting the thread limit:

$img->setResourceLimit(6, 1); // 6 means "thread limit" resource, 1 means limit 
threads to 1.
 [2012-04-18 21:58 UTC] luminarior at gmail dot com
OK, I'll try to set ResourceLimit and see what will happen.
 [2012-04-18 22:29 UTC] luminarior at gmail dot com
I've just tried to get threads' type ResourceLimit value:
$im->getResourceLimit(6);
It is set to 4 in my case.
Then I tried to set
$im->setResourceLimit(6, 1);
And script completed fine without any problems.
Then, I tried to set 1 additional thread with:
$im->setResourceLimit(6, 2);
And the script gave me segfault again.
I think it's your problem guys with threads. So you should fix it somehow.
 [2012-04-18 22:32 UTC] luminarior at gmail dot com
BTW, I'm using the following versions of software and still getting segfaults:
dev-lang/php-5.3.10
dev-php/pecl-imagick-3.1.0_rc1
media-gfx/imagemagick-6.7.6.4
 [2013-12-03 11:31 UTC] mike@php.net
-Assigned To: +Assigned To: mkoppanen
 [2015-01-08 22:27 UTC] danack@php.net
-Status: Assigned +Status: Wont fix
 [2015-01-08 22:27 UTC] danack@php.net
Hi, 

Unfortunately there is nothing to fix in the Imagick code to address the problem. The issue is caused by the OpenMP library that is present on your system.

There is no way to fix it as the Imagick code doesn't call it; instead Imagick calls the ImageMagick code, which in turns calls the OpenMP library.

For future reference, please could you say which version of libgomp you have on your system - or whichever package is providing the OpenMP implementation.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Jul 24 06:01:27 2019 UTC