|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-02-19 20:34 UTC] jan at horde dot org
I get this warning message while trying to run iconv():
Warning: String is not zero-terminated (before?afterZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ?̏*p) (source: ./zend_execute.c:449) in /usr/local/httpd/htdocs/headhorde/iconv.php on line 9
PHP is compiled against the latest inconv library.
This test script reproduces the messages:
<pre>
<?
error_reporting(E_ALL);
$src = 'ISO-8859-1';
$dst = 'ISO-8859-2';
$j = 0;
for($i=1;$i<=255;$i++) {
$tst = sprintf('before%cafter',$i);
$rc=iconv($src,$dst,$tst);
if (strlen($rc) == 0) {
print "$i fail";
$j++;
}
print "\n";
}
print "total failed: $j";
?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 08:00:01 2025 UTC |
If anyone can get use of it, this is the strace result. If I interpret it correctly there is a segfault but it isn't reported in the apache logs. accept(20, {sin_family=AF_INET, sin_port=htons(1658), sin_addr=inet_addr("192.168.60.136")}}, [16]) = 4 rt_sigaction(SIGUSR1, {SIG_IGN}, {0x805e4b0, [], SA_INTERRUPT|0x4000000}, 8) = 0 getsockname(4, {sin_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("80.130.200.232")}}, [16]) = 0 setsockopt(4, IPPROTO_TCP1, [1], 4) = 0 brk(0x8180000) = 0x8180000 brk(0x8183000) = 0x8183000 alarm(60) = 0 read(4, "GET /headhorde/iconv.php HTTP/1."..., 4096) = 367 rt_sigaction(SIGUSR1, {SIG_IGN}, {SIG_IGN}, 8) = 0 time(NULL) = 1014214048 alarm(60) = 60 alarm(0) = 60 gettimeofday({1014214048, 189959}, NULL) = 0 stat64("/usr/local/httpd/htdocs/headhorde/iconv.php", {st_mode=S_IFREG|0644, st_size=390, ...}) = 0 lstat64("/usr", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/usr/local", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/usr/local/httpd", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/usr/local/httpd/htdocs", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 alarm(60) = 0 umask(077) = 022 umask(022) = 077 brk(0x8186000) = 0x8186000 setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={30, 0}}, NULL) = 0 rt_sigaction(SIGPROF, {0x4031cc50, [], SA_RESTART|0x4000000}, {SIG_DFL}, 8) = 0 rt_sigprocmask(SIG_UNBLOCK, [PROF], NULL, 8) = 0 brk(0x8187000) = 0x8187000 brk(0x8188000) = 0x8188000 brk(0x8189000) = 0x8189000 brk(0x818a000) = 0x818a000 brk(0x818b000) = 0x818b000 brk(0x818c000) = 0x818c000 brk(0x818d000) = 0x818d000 brk(0x818e000) = 0x818e000 time(NULL) = 1014214048 getpid() = 30325 gettimeofday({1014214048, 215019}, NULL) = 0 getpid() = 30325 getcwd("/root/cvs/cvsphp", 4095) = 17 chdir("/usr/local/httpd/htdocs/headhorde") = 0 open("/usr/local/httpd/htdocs/headhorde/iconv.php", O_RDONLY|O_LARGEFILE) = 6 getcwd("/usr/local/httpd/htdocs/headhorde", 4095) = 34 lstat("/usr", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/usr/local", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/usr/local/httpd", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/usr/local/httpd/htdocs", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/usr/local/httpd/htdocs/headhorde", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/usr/local/httpd/htdocs/headhorde/iconv.php", {st_mode=S_IFREG|0644, st_size=390, ...}) = 0 brk(0x8193000) = 0x8193000 ioctl(6, TCGETS, 0xbfffe0ac) = -1 ENOTTY (Inappropriate ioctl for device) read(6, "<pre>\r\n<?\r\n error_reporting(E_A"..., 8192) = 390 read(6, "", 7802) = 0 read(6, "", 8192) = 0 ioctl(6, TCGETS, 0xbfffd088) = -1 ENOTTY (Inappropriate ioctl for device) close(6) = 0 alarm(60) = 60 alarm(0) = 60 chdir("/root/cvs/cvsphp") = 0 rt_sigaction(SIGSEGV, {SIG_DFL}, {SIG_DFL}, 8) = 0 setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0 umask(022) = 022 alarm(0) = 0 alarm(60) = 0 alarm(0) = 60 select(5, [4], NULL, NULL, {0, 0}) = 0 (Timeout) write(4, "HTTP/1.1 200 OK\r\nDate: Wed, 20 F"..., 999) = 999 time(NULL) = 1014214048 write(21, "192.168.60.136 - - [20/Feb/2002:"..., 158) = 158 gettimeofday({1014214048, 297068}, NULL) = 0 times({tms_utime=256, tms_stime=67, tms_cutime=0, tms_cstime=0}) = 60732594 rt_sigaction(SIGUSR1, {0x805e4b0, [], SA_INTERRUPT|0x4000000}, {SIG_IGN}, 8) = 0 alarm(15) = 0The latest changes in ext/iconv/iconv.c (rev. 1.27, 1.28) are wrong. I suggest to revert to version 1.26 and then apply the right fix (below). I sent that patch but failed to verify that it was applied correctly to CVS (I have it applied to php-4.0.6 on my runnung system). --- ext/iconv/iconv.c.1.26 Wed Feb 27 08:40:51 2002 +++ ext/iconv/iconv.c Wed Feb 27 08:42:35 2002 @@ -167,7 +167,7 @@ } *out_len = out_size - out_left; - out[*out_len] = '\0'; + out_buffer[*out_len] = '\0'; icv_close(cd); return SUCCESS; ---- Writing the null byte to out[*out_len] is actually assigining a NULL pointer at some random location and may cause a seg. fault or other weird behavior. On a second thought, this should work just as well: *out_p = '\0'; Using calloc instead of malloc is less efficient as it needs to zero all the bytes in the returned string. Adding 1 to the length (as the hange in 1.28) actually increases the length of the result - which is not what we wanted. Try this small program to see the result: <? $src = 'ISO-8859-1'; $dst = 'ISO-8859-2'; $f = "Hello world."; $t = iconv($src,$dst,$f); printf("strlen('%s') = %d\nstrlen('%s') = %d\n", $f, strlen($f), $t, strlen($t)); ?>