rasmus          Tue Jan 29 23:29:04 2008 UTC

  Modified files:              
    /php-src/ext/xml    xml.c 
    /php-src/ext/xml/tests      bug43957.phpt 
  Log:
  Fixed bug #43957
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/xml/xml.c?r1=1.174&r2=1.175&diff_format=u
Index: php-src/ext/xml/xml.c
diff -u php-src/ext/xml/xml.c:1.174 php-src/ext/xml/xml.c:1.175
--- php-src/ext/xml/xml.c:1.174 Mon Dec 31 07:12:17 2007
+++ php-src/ext/xml/xml.c       Tue Jan 29 23:29:04 2008
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: xml.c,v 1.174 2007/12/31 07:12:17 sebastian Exp $ */
+/* $Id: xml.c,v 1.175 2008/01/29 23:29:04 rasmus Exp $ */
 
 #define IS_EXT_MODULE
 
@@ -591,15 +591,27 @@
        while (pos > 0) {
                c = (unsigned char)(*s);
                if (c >= 0xf0) { /* four bytes encoded, 21 bits */
-                       c = ((s[0]&7)<<18) | ((s[1]&63)<<12) | ((s[2]&63)<<6) | 
(s[3]&63);
+                       if(pos-4 >= 0) {
+                               c = ((s[0]&7)<<18) | ((s[1]&63)<<12) | 
((s[2]&63)<<6) | (s[3]&63);
+                       } else {
+                               c = '?';        
+                       }
                        s += 4;
                        pos -= 4;
                } else if (c >= 0xe0) { /* three bytes encoded, 16 bits */
-                       c = ((s[0]&63)<<12) | ((s[1]&63)<<6) | (s[2]&63);
+                       if(pos-3 >= 0) {
+                               c = ((s[0]&63)<<12) | ((s[1]&63)<<6) | 
(s[2]&63);
+                       } else {
+                               c = '?';
+                       }
                        s += 3;
                        pos -= 3;
                } else if (c >= 0xc0) { /* two bytes encoded, 11 bits */
-                       c = ((s[0]&63)<<6) | (s[1]&63);
+                       if(pos-3 >= 0) {
+                               c = ((s[0]&63)<<6) | (s[1]&63);
+                       } else {
+                               c = '?';
+                       }
                        s += 2;
                        pos -= 2;
                } else {
http://cvs.php.net/viewvc.cgi/php-src/ext/xml/tests/bug43957.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/xml/tests/bug43957.phpt
diff -u /dev/null php-src/ext/xml/tests/bug43957.phpt:1.2
--- /dev/null   Tue Jan 29 23:29:04 2008
+++ php-src/ext/xml/tests/bug43957.phpt Tue Jan 29 23:29:04 2008
@@ -0,0 +1,13 @@
+--TEST--
+Bug #43957 - utf8_decode() bogus conversion on multibyte indicator near end of 
string
+--SKIPIF--
+<?php
+require_once("skipif.inc");
+if (!extension_loaded('xml')) die ("skip xml extension not available");
+?>
+--FILE--
+<?php
+  echo utf8_decode('abc'.chr(0xe0));
+?>
+--EXPECTF--
+abc?

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to