php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53844 PHP built from source on Solaris gets SIGSEGV with libiconv
Submitted: 2011-01-26 08:48 UTC Modified: 2013-02-18 00:34 UTC
Votes:7
Avg. Score:4.4 ± 0.7
Reproduced:7 of 7 (100.0%)
Same Version:5 (71.4%)
Same OS:6 (85.7%)
From: r at rcrowley dot org Assigned:
Status: No Feedback Package: ICONV related
PHP Version: 5.3.5 OS: Solaris
Private report: No CVE-ID: None
 [2011-01-26 08:48 UTC] r at rcrowley dot org
Description:
------------
With PHP built from source on a Joyent SmartMachine and using the operating 
system's libiconv, simple uses of the PHP iconv function result in SIGSEGV.

PHP builds without (related) warnings and is linked to the libiconv shared 
library:

[root@gnp2b7ak ~]# ldd $(which php) | grep iconv
        libiconv.so.2 =>         /opt/local/lib/libiconv.so.2
[root@gnp2b7ak ~]#

We're using the following configuration:

./configure \
	--disable-ctype \
	--disable-dom \
	--disable-fileinfo \
	--disable-flatfile \
	--disable-inifile \
	--disable-ipv6 \
	--disable-memcache-session \
	--disable-phar \
	--disable-posix \
	--disable-session \
	--disable-simplexml \
	--disable-xmlwriter \
	--enable-mbstring \
	--enable-memcache \
	--host=i386-sun-solaris2 \
	--mandir=/opt/local/man \
	--prefix=/opt/local \
	--with-apxs2=/opt/local/apache2/bin/apxs \
	--with-config-file-path=/opt/local/etc \
	--with-curl \
	--with-gd \
	--with-jpeg-dir=/opt/local \
	--with-libxml-dir=/opt/local \
	--with-mcrypt \
	--with-mysql=mysqlnd \
	--with-openssl=/opt/local \
	--with-iconv \
	--without-pdo-sqlite \
	--without-sqlite \
	--without-sqlite3 \
	--with-pdo-mysql=mysqlnd \
	--with-pear \
	--with-png-dir=/opt/local \
	--with-regex=system \
	--with-zlib \
	--with-zlib-dir=/usr

Test script:
---------------
php -r 'echo iconv("UTF-8", "UTF-8", "Hello, world.\n");'

Expected result:
----------------
[root@gnp2b7ak ~]# php -r 'echo iconv("UTF-8", "UTF-8", "Hello, world.\n");'
Hello, world.
[root@gnp2b7ak ~]#

Actual result:
--------------
[root@gnp2b7ak ~]# php -r 'echo iconv("UTF-8", "UTF-8", "Hello, world.\n");'
Segmentation Fault (core dumped)
[root@gnp2b7ak ~]#

Note that the iconv(1) program works fine:

[root@gnp2b7ak ~]# echo "Hello, world." | /opt/local/bin/iconv -f UTF-8 -t UTF-8
Hello, world.
[root@gnp2b7ak ~]#

(gdb) bt
#0  0xec835356 in ?? ()
#1  0xfe8d68ab in iconv () from /lib/libc.so.1
#2  0x08156b59 in php_iconv_string (in_p=0x860d478 "Hello, world.\n", in_len=14, 
out=0x80475c0, out_len=0x80475c4, out_charset=0x860d44c "UTF-8", 
    in_charset=0x860e8f4 "UTF-8") at /tmp/tmp.qsay1T/php-
5.3.4/ext/iconv/iconv.c:501
#3  0x08159b1c in php_if_iconv (ht=3, return_value=0x860d490, 
return_value_ptr=0x0, this_ptr=0x0, return_value_used=1)
    at /tmp/tmp.qsay1T/php-5.3.4/ext/iconv/iconv.c:2327
#4  0x082d4cfa in zend_do_fcall_common_helper_SPEC (execute_data=0x8746430) at 
zend_vm_execute.h:316
#5  0x082d3d79 in execute (op_array=0x860d378) at zend_vm_execute.h:107
#6  0x082a7429 in zend_eval_stringl (str=0x8047d0b "echo iconv(\"UTF-8\", \"UTF-
8\", \"Hello, world.\\n\");", str_len=48, retval_ptr=0x0, 
    string_name=0x858210c "Command line code") at /tmp/tmp.qsay1T/php-
5.3.4/Zend/zend_execute_API.c:1193
#7  0x082a75e2 in zend_eval_stringl_ex (str=0x8047d0b "echo iconv(\"UTF-8\", 
\"UTF-8\", \"Hello, world.\\n\");", str_len=48, retval_ptr=0x0, 
    string_name=0x858210c "Command line code", handle_exceptions=1) at 
/tmp/tmp.qsay1T/php-5.3.4/Zend/zend_execute_API.c:1235
#8  0x082a765a in zend_eval_string_ex (str=0x8047580 "\016", retval_ptr=0x0, 
string_name=0x858210c "Command line code", handle_exceptions=1)
    at /tmp/tmp.qsay1T/php-5.3.4/Zend/zend_execute_API.c:1246
#9  0x08336c40 in main (argc=3, argv=0x8047c24) at /tmp/tmp.qsay1T/php-
5.3.4/sapi/cli/php_cli.c:1282
(gdb)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-26 08:50 UTC] r at rcrowley dot org
This problem is not limited to one odd Joyent SmartMachine.  The problem exists on 
several not quite identical machines.
 [2011-02-01 21:48 UTC] jacques@php.net
Hi Richard,

Can you confirm which versions of iconv you have installed?

pkg_info | grep iconv

Should give you the information.
 [2011-02-07 17:16 UTC] r at rcrowley dot org
# iconv --version
iconv (GNU libiconv 1.11)
Copyright (C) 2000-2007 Free Software Foundation, Inc.
License GPLv2+: GNU GPL version 2 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.
Written by Bruno Haible.
# pkgin list | grep iconv
libiconv-1.12nb1     Character set conversion library
#
 [2011-02-07 19:46 UTC] johannes@php.net
-Status: Open +Status: Feedback
 [2011-02-07 19:46 UTC] johannes@php.net
Which version of solaris are you using? My Solaris 11 express works fine. Could you also try doing a

./configure --disable-iconv --with-iconv

build? Yor stacktrace shows 
   #1  0xfe8d68ab in iconv () from /lib/libc.so.1
so the libc's iconv is being used. My assumption is that another library is using iconv from /opt/local and so the linker pulls the libs in the wrong order so one version is used for compiling PHP the other for running ...
 [2011-02-07 20:55 UTC] phil at quizlet dot com
(I'm working with Richard on this...)

[root@gnp2b7ak ~]# showrev
Hostname: ...
Hostid: c54426
Release: 5.11
Kernel architecture: i86pc
Application architecture: i386
Hardware provider: 
Domain: 
Kernel version: SunOS 5.11 snv_121

Joyent (the hosting provider) has kindly offered a free Joyent Solaris instance 
for you to test against, if you'd like. Just email me and I'll get it set up.
 [2011-02-08 03:23 UTC] srinatar@php.net
what happens when you do some thing like
LD_LIBRARY_PATH=/opt/local/lib ; export LD_LIBRARY_PATH ; php -r 'echo iconv("UTF-8", "UTF-8", "Hello, world.\n");'
 [2011-02-09 01:15 UTC] phil at quizlet dot com
No luck...

With the original configuration, I tried:

# LD_LIBRARY_PATH=/opt/local/lib ; export LD_LIBRARY_PATH ; php -r 'echo 
iconv("UTF-8", "UTF-8", "Hello, world.\n");'

as well as:

# LD_LIBRARY_PATH=/opt/local/lib php -r 'echo iconv("UTF-8", "UTF-8", "Hello, 
world.\n");'

as well as reconfiguring with:

# ./configure --disable-iconv --with-iconv

and also tried:

# ./configure LDFLAGS=/opt/local/lib --with-iconv

and:

# ./configure LDFLAGS=/opt/local/lib --disable-iconv --with-iconv

Note: I did get a "Notice: Following unknown configure options were used: --
disable-iconv" when trying to follow johannes advice, and --disable-iconv isn't 
listed in ./configure --help.

In ALL of the above cases when testing PHP's iconv() I got a segfault and 
checked the backtrace with gdb after each and they were all identical:

(gdb) bt
#0  0xec835356 in ?? ()
#1  0xfe8d68ab in iconv () from /lib/libc.so.1
#2  0x0815a2b1 in php_iconv_string (in_p=0x8653484 "Hello, world.\n", in_len=14, 
out=0x8047580, out_len=0x8047584, out_charset=0x8653458 "UTF-8", 
in_charset=0x8654900 "UTF-8")
    at /tmp/tmp..Aa4sh/php-5.3.5/ext/iconv/iconv.c:501
#3  0x0815d274 in php_if_iconv (ht=3, return_value=0x865349c, 
return_value_ptr=0x0, this_ptr=0x0, return_value_used=1) at /tmp/tmp..Aa4sh/php-
5.3.5/ext/iconv/iconv.c:2327
#4  0x083147de in zend_do_fcall_common_helper_SPEC (execute_data=0x8793f70) at 
zend_vm_execute.h:316
#5  0x0831385d in execute (op_array=0x8653384) at zend_vm_execute.h:107
#6  0x082e6e29 in zend_eval_stringl (str=0x8047ccb "echo iconv(\"UTF-8\", \"UTF-
8\", \"Hello, world.\\n\");", str_len=48, retval_ptr=0x0, string_name=0x85c30ae 
"Command line code")
    at /tmp/tmp..Aa4sh/php-5.3.5/Zend/zend_execute_API.c:1193
#7  0x082e6fe2 in zend_eval_stringl_ex (str=0x8047ccb "echo iconv(\"UTF-8\", 
\"UTF-8\", \"Hello, world.\\n\");", str_len=48, retval_ptr=0x0, 
string_name=0x85c30ae "Command line code", 
    handle_exceptions=1) at /tmp/tmp..Aa4sh/php-
5.3.5/Zend/zend_execute_API.c:1235
#8  0x082e705a in zend_eval_string_ex (str=0x8047540 "\016", retval_ptr=0x0, 
string_name=0x85c30ae "Command line code", handle_exceptions=1) at 
/tmp/tmp..Aa4sh/php-5.3.5/Zend/zend_execute_API.c:1246
#9  0x08376724 in main (argc=3, argv=0x8047bdc) at /tmp/tmp..Aa4sh/php-
5.3.5/sapi/cli/php_cli.c:1282

Any other ideas?
 [2011-02-09 11:34 UTC] johannes@php.net
I meant to write --disable-all, sorry for the mistake. Could you try

   ./configure --disable-all --with-iconv && make && ./sapi/cli/php -r 'echo iconv("UTF-8", "UTF-8", "Hello, world.\n");'
 [2011-02-09 19:00 UTC] phil at quizlet dot com
I ran it exactly as you wrote, still got a "Segmentation Fault (core dumped)"

[root@gnp2b7ap /opt/sourceinstall/php-5.3.5]# /root/gdb/bin/gdb ./sapi/cli/php 
core
GNU gdb 6.2.1
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-sun-solaris2"...
Core was generated by `./sapi/cli/php -r echo iconv("UTF-8", "UTF-8", "Hello, 
world.\n");'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /lib/libresolv.so.2...done.
Loaded symbols for /lib/libresolv.so.2
Reading symbols from /opt/local/lib/libiconv.so.2...done.
Loaded symbols for /opt/local/lib/libiconv.so.2
Reading symbols from /lib/librt.so.1...
warning: Lowest section in /lib/librt.so.1 is .dynamic at 00000074
done.
Loaded symbols for /lib/librt.so.1
Reading symbols from /lib/libm.so.2...done.
Loaded symbols for /lib/libm.so.2
Reading symbols from /lib/libnsl.so.1...done.
Loaded symbols for /lib/libnsl.so.1
Reading symbols from /lib/libsocket.so.1...done.
Loaded symbols for /lib/libsocket.so.1
Reading symbols from /lib/libc.so.1...done.
Loaded symbols for /lib/libc.so.1
Reading symbols from /opt/gcc/lib/libgcc_s.so.1...done.
Loaded symbols for /opt/gcc/lib/libgcc_s.so.1
Reading symbols from /usr/lib/locale/en_US.ISO8859-1/en_US.ISO8859-
1.so.3...done.
Loaded symbols for /usr/lib/locale/en_US.ISO8859-1/en_US.ISO8859-1.so.3
#0  0xec835356 in ?? ()
(gdb) bt
#0  0xec835356 in ?? ()
#1  0xfebc68ab in iconv () from /lib/libc.so.1
#2  0x080d9141 in php_iconv_string (in_p=0x8308488 "Hello, world.\n", in_len=14, 
out=0x8047624, out_len=0x8047628, out_charset=0x830845c "UTF-8", 
in_charset=0x8309904 "UTF-8")
    at /opt/sourceinstall/php-5.3.5/ext/iconv/iconv.c:501
#3  0x080dbb0c in php_if_iconv (ht=3, return_value=0x83084a0, 
return_value_ptr=0x0, this_ptr=0x0, return_value_used=1) at 
/opt/sourceinstall/php-
5.3.5/ext/iconv/iconv.c:2327
#4  0x081caac5 in zend_do_fcall_common_helper_SPEC (execute_data=0x83ec520) at 
zend_vm_execute.h:316
#5  0x081c9ec2 in execute (op_array=0x8308388) at zend_vm_execute.h:107
#6  0x081a1e3f in zend_eval_stringl (str=0x8047ce6 "echo iconv(\"UTF-8\", \"UTF-
8\", \"Hello, world.\\n\");", str_len=0, retval_ptr=0x0, string_name=0x82b9ec9 
"Command line code")
    at /opt/sourceinstall/php-5.3.5/Zend/zend_execute_API.c:1193
#7  0x081a1fdb in zend_eval_stringl_ex (str=0x8047ce6 "echo iconv(\"UTF-8\", 
\"UTF-8\", \"Hello, world.\\n\");", str_len=48, retval_ptr=0x0, 
string_name=0x82b9ec9 "Command line code", 
    handle_exceptions=1) at /opt/sourceinstall/php-
5.3.5/Zend/zend_execute_API.c:1235
#8  0x081a2035 in zend_eval_string_ex (str=0x80475e0 "\016", retval_ptr=0x0, 
string_name=0x82b9ec9 "Command line code", handle_exceptions=1)
    at /opt/sourceinstall/php-5.3.5/Zend/zend_execute_API.c:1246
#9  0x08223584 in main (argc=3, argv=0x8047bf0) at /opt/sourceinstall/php-
5.3.5/sapi/cli/php_cli.c:1282
 [2011-02-10 01:59 UTC] srinatar@php.net
As Johannes and the core dump output show this has nothing to do with php core. this is a compilation issue mainly due to the way your environment is set up. 

this is what i did

- unset LD_LIBRARY_PATH
- installed libiconv in /opt/local
- compiled php as ./configure --disable-all --with-iconv=/opt/local
- ldd sapi/cli/php | grep iconv and verify that PHP is depending on /opt/local/lib
- ./sapi/cli/php -r 'echo iconv("UTF-8", "UTF-8", "Hello, world.\n");'

and got the expected results..

note: i did use the OS provided gcc for my compilation needs. 

pl. note that i see that you have compiled and installed other dependent libraries at /opt/local as well. you might want to ensure that when you compiled those - they all depend on /opt/local/lib as well. it is not a good idea to mix between OS provided iconv libraries vs what you compiled.

i would like to close this bug as not a valid bug if others don't have any issue.
 [2011-02-11 19:06 UTC] phil at quizlet dot com
Thanks for the help.

We got it working with:
./configure --with-iconv=/opt/local

It seems like it could be really helpful for people if there was anyway for the 
compiler to test for this case so that if people just specify "--with-iconv" they 
don't get hard-to-debug seg faults.
 [2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 [2013-03-28 13:23 UTC] katsuhiko dot tanno at gmail dot com
# setenv LD_PRELOAD_32 /your/libiconv/path/preloadable_libiconv.so

And just invoke command.

# php -r 'echo iconv("UTF-8", "UTF-8", "Hello, world.\n");'
Hello, world.
#

About what LD_PRELOAD_32 is, please go GNU libiconv web page or ld.so.1(1) man page.
http://www.gnu.org/software/libiconv/
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 01 20:01:29 2024 UTC