php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15638 warning from zend_execute.c while running inconv()
Submitted: 2002-02-19 20:34 UTC Modified: 2002-02-20 11:17 UTC
From: jan at horde dot org Assigned:
Status: Closed Package: ICONV related
PHP Version: 4.0CVS-2002-02-19 OS: Linux
Private report: No CVE-ID: None
 [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";
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-20 02:24 UTC] derick@php.net
I committed a fix for this to CVS, but was not be able to test it. Would you be so kind to take the honors?

Derick
 [2002-02-20 06:31 UTC] jan at horde dot org
The warnings have dispappeared. Now there's no output generated at all, but that's another problem.
 [2002-02-20 08:26 UTC] sander@php.net
> Now there's no output generated at all,
> but that's another problem.
You mean it's a problem in your script and not in PHP? In that case, please close this bug.
 [2002-02-20 08:32 UTC] jan at horde dot org
No, it's still an iconv/php problem but I have to investigate further. If you look at the test script you see that it should generate ANY output. And there are no segfaults. Hm.
 [2002-02-20 08:35 UTC] derick@php.net
Did you compile with or without debug?

Derick
 [2002-02-20 08:52 UTC] jan at horde dot org
With. But unfortunately my apache is without.
 [2002-02-20 09:44 UTC] jan at horde dot org
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)                               = 0
 [2002-02-20 09:46 UTC] derick@php.net
I'm just recompiling PHP with iconv support to check it out. Assinging to myself.

Derick
 [2002-02-20 10:53 UTC] derick@php.net
Now it's fixed (i hope :)

Derick
 [2002-02-20 11:17 UTC] jan at horde dot org
Yes, seems to be working now again. Thanks!
Now I can start doing something useful with it. :-)

Just to let you know, compiling gave me the following warning but it seems to be harmless:
iconv.c: In function `php_iconv_string':
iconv.c:162: warning: passing arg 2 of `libiconv' from incompatible pointer type
 [2002-02-27 02:15 UTC] itai at siftology dot com
The 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));

?>
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Dec 02 02:01:23 2020 UTC