Edit report at https://bugs.php.net/bug.php?id=61362&edit=1
ID: 61362
Updated by: cmb@php.net
Reported by: sam at rmcreative dot ru
Summary: Exception::getTraceAsString, Exception::__toString
not able to handle unicode
Status: Assigned
Type: Bug
Package: Unicode Engine related
Operating System: All
-PHP Version: 5.4.0
+PHP Version: 7.0.0
Assigned To: johannes
Block user comment: N
Private report: N
New Comment:
See <http://3v4l.org/ONJBe>. As of PHP 5.4.29 the result
is
correct, but master shows a regression.
The problem is that c is declared as char[1], what is a signed
value, but the following calculations assume it is unsigned.
Simply declaring
unsigned char c = s[i];
should solve the problem.
I'm working on a PR (including a respective test).
[1] <http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_exceptions.c#402>
Previous Comments:
------------------------------------------------------------------------
[2012-03-14 17:20:50] tony2001@php.net
The problem is here: http://lxr.php.net/opengrok/xref/PHP_5_4/Zend/zend_exceptions.c#391
Dunno what to do in this case: either add to the docs that the result of getTraceAsString() is
perfectly safe from binary symbols or drop that code completely and allow any chars there.
------------------------------------------------------------------------
[2012-03-14 15:16:42] sam at rmcreative dot ru
It's UTF8 already.
------------------------------------------------------------------------
[2012-03-14 15:14:58] tony2001@php.net
Nevermind, I see the problem.
------------------------------------------------------------------------
[2012-03-14 12:20:41] tony2001@php.net
What if you try to switch your browser encoding to UTF8 from whatever it is by default?
------------------------------------------------------------------------
[2012-03-12 15:44:18] sam at rmcreative dot ru
Description:
------------
Exception::getTraceAsString, Exception::__toString are not able to properly handle unicode in stack
trace. Instead of showing actual argument values it's giving ???? in case value is unicode.
Tested on PHP 5.3 and PHP 5.4.
Test script:
---------------
<?php
function test($arg){
throw new Exception();
}
try {
test('ÑеÑÑ');
}
catch(Exception $e) {
echo $e->getTraceAsString();
echo (string)$e;
}
Expected result:
----------------
d:\web\usr\local\php54>php.exe d:\src\exception_wrong_trace\test.php
#0 D:\src\exception_wrong_trace\test.php(7): test('ÑеÑÑ')
#1 {main}exception 'Exception' in D:\src\exception_wrong_trace\test.php:3
Stack trace:
#0 D:\src\exception_wrong_trace\test.php(7): test('ÑеÑÑ')
#1 {main}
Actual result:
--------------
d:\web\usr\local\php54>php.exe d:\src\exception_wrong_trace\test.php
#0 D:\src\exception_wrong_trace\test.php(7): test('????')
#1 {main}exception 'Exception' in D:\src\exception_wrong_trace\test.php:3
Stack trace:
#0 D:\src\exception_wrong_trace\test.php(7): test('????')
#1 {main}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61362&edit=1