diff options
Diffstat (limited to 'ext/xml')
| -rw-r--r-- | ext/xml/compat.c | 2 | ||||
| -rw-r--r-- | ext/xml/expat_compat.h | 4 | ||||
| -rw-r--r-- | ext/xml/php_xml.h | 4 | ||||
| -rw-r--r-- | ext/xml/tests/bug43957.phpt | 13 | ||||
| -rw-r--r-- | ext/xml/xml.c | 22 |
5 files changed, 35 insertions, 10 deletions
diff --git a/ext/xml/compat.c b/ext/xml/compat.c index 32f4cc806..7b4c90dbd 100644 --- a/ext/xml/compat.c +++ b/ext/xml/compat.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | diff --git a/ext/xml/expat_compat.h b/ext/xml/expat_compat.h index 9200b1f0e..7eb3236b0 100644 --- a/ext/xml/expat_compat.h +++ b/ext/xml/expat_compat.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: expat_compat.h,v 1.19.2.1.2.1 2007/01/01 09:36:09 sebastian Exp $ */ +/* $Id: expat_compat.h,v 1.19.2.1.2.2 2007/12/31 07:20:14 sebastian Exp $ */ #ifndef PHP_EXPAT_COMPAT_H #define PHP_EXPAT_COMPAT_H diff --git a/ext/xml/php_xml.h b/ext/xml/php_xml.h index f5c1b1e69..f975c21d5 100644 --- a/ext/xml/php_xml.h +++ b/ext/xml/php_xml.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_xml.h,v 1.28.2.2.2.3 2007/01/01 09:36:09 sebastian Exp $ */ +/* $Id: php_xml.h,v 1.28.2.2.2.4 2007/12/31 07:20:14 sebastian Exp $ */ #ifndef PHP_XML_H #define PHP_XML_H diff --git a/ext/xml/tests/bug43957.phpt b/ext/xml/tests/bug43957.phpt new file mode 100644 index 000000000..34ddcd951 --- /dev/null +++ b/ext/xml/tests/bug43957.phpt @@ -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? diff --git a/ext/xml/xml.c b/ext/xml/xml.c index 0c7ebf887..2fb994ddd 100644 --- a/ext/xml/xml.c +++ b/ext/xml/xml.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: xml.c,v 1.157.2.4.2.5 2007/01/01 09:36:09 sebastian Exp $ */ +/* $Id: xml.c,v 1.157.2.4.2.8 2008/01/30 08:50:02 rasmus Exp $ */ #define IS_EXT_MODULE @@ -579,15 +579,27 @@ PHPAPI char *xml_utf8_decode(const XML_Char *s, int len, int *newlen, const XML_ 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-2 >= 0) { + c = ((s[0]&63)<<6) | (s[1]&63); + } else { + c = '?'; + } s += 2; pos -= 2; } else { |
