# Stuck debugging a PHP6 string-->unicode-->string conversion problem on Solaris (SPARC)

- Thread: https://externals.io/message/46040
- Original archive: https://news-web.php.net/php.internals/46040
- Started by Arvind Srinivasan on 2009-11-13T13:44:10+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #46040 — Arvind Srinivasan — 2009-11-13T13:44:10+00:00

URL: https://externals.io/message/46040#46040

Hi,

I need some help debugging a test failure
(./ext/spl/tests/DirectoryIterator_getBasename_basic_test goes into an
infinite loop) on Solaris 10 (SPARC) with PHP6 trunk.

I've narrowed the problem down to a difference between what
zspprintf() converts to unicode and is then subsequently converted to
string by zend_unicode_to_string_ex().

spl_filesystem_object_get_file_name creates a unicoded pathname (to an
entry in a directory) by invoking zspprintf:
intern->file_name_len = zspprintf(path_type, &intern->file_name, 0,
"%R%c%s", path_type, path.v, slash, intern->u.dir.entry.d_name);

php_u_stat on intern->file_name ends up calling
num_conv = zend_unicode_to_string_ex(ZEND_U_CONVERTER(UG(filesystem_encoding_conv)),
pathenc, pathenc_len, path, path_len, &status);
in main/streams/streams.c

After this call, pathenc contains garbage characters in place of what
was written into intern->file_name by zspprint for %c%s. Whatever was
written in as %R comes out correctly in pathenc.

As a test, I tried the following:
intern->file_name_len = zspprintf(path_type, &intern->file_name, 0, "/tmp/.");
zend_unicode_to_string_ex(ZEND_U_CONVERTER(UG(filesystem_encoding_conv)),
&pathenc, pathenc_len, intern->file_name.u, intern->file_name_len,
&status);

Here's my debugger session which shows that I don't get back the
string '/tmp/.' from zend_unicode_to_string_ex.
(dbx 9) list 204,208
  204                           intern->file_name_len =
zspprintf(path_type, &intern->file_name, 0, "/tmp/.");
  205
  206
zend_unicode_to_string_ex(ZEND_U_CONVERTER(UG(filesystem_encoding_conv)),
  207                                   &pathenc, pathenc_len,
intern->file_name.u, intern->file_name_len, &status);

(dbx 10) n
t@1 (l@1) stopped in spl_filesystem_object_get_file_name at line 207
in file "spl_directory.c"
  207                                   &pathenc, pathenc_len,
intern->file_name.u, intern->file_name_len, &status);

(dbx 11) print intern->file_name_len
intern->file_name_len = 6

(dbx 12) examine intern->file_name.v/12c
0x00fd4b88:      '/' '\0' 't' '\0' 'm' '\0' 'p' '\0' '/' '\0' '.' '\0'

(dbx 13) n
t@1 (l@1) stopped in spl_filesystem_object_get_file_name at line 213
in file "spl_directory.c"
  213                           intern->file_name_type = path_type;

(dbx 14) print status
status = U_ZERO_ERROR

(dbx 15) print *pathenc_len
*pathenc_len = 18

(dbx 16) x pathenc/18c
0x00fd3860:      '�' '�' '�' '�' '�' '�' '�' '�' '�' '�' '�' '�' '�' '�' '�' '�'
0x00fd3870:      '�' '�'

(dbx 17) p pathenc
pathenc = 0xfd3860
"\xe2\xbc\x80\xe7\x90\x80\xe6\xb4\x80\xe7\x80\x80\xe2\xbc\x80\xe2\xb8\x80"

How should I proceed?

Thanks,
Arvi

---

## #46054 — Arvind Srinivasan — 2009-11-16T12:23:40+00:00

URL: https://externals.io/message/46040#46054 · In reply to: #46040

I think I've found the cause of the problem.

I have created  a bug and attached a patch to
http://bugs.php.net/?id=50189


Arvi

---

## #46065 — Christopher Jones — 2009-11-16T18:21:09+00:00

URL: https://externals.io/message/46040#46065 · In reply to: #46054

Arvind Srinivasan wrote:
 > I think I've found the cause of the problem.
 >
 > I have created  a bug and attached a patch to
 > http://bugs.php.net/?id=50189
 >
 >
 > Arvi
 >

What about basing the #ifdef on WORDS_BIGENDIAN?  This appears to be
defined during PHP configuration (see alocal.m4 and acinclude.m4).

Chris

-- 
Blog: http://blogs.oracle.com/opal
Twitter:  http://twitter.com/ghrd

---

## #46069 — Arvind Srinivasan — 2009-11-17T10:52:10+00:00

URL: https://externals.io/message/46040#46069 · In reply to: #46065

thanks. i've updated the patch in the bug report to use WORDS_BIGENDIAN.
