ID:               40664
 Updated by:       [EMAIL PROTECTED]
 Reported By:      fjortiz at comunet dot es
 Status:           Open
 Bug Type:         COM related
 Operating System: Win32
 PHP Version:      5.2.1
 New Comment:

Unfortunately the extension is currently unmaintained, so I don't think
anybody is going to commit your patch in the nearest future.



Previous Comments:
------------------------------------------------------------------------

[2007-05-23 11:51:16] fjortiz at comunet dot es

Any updates about this?. I'm showing you the code so fix the issue.
Please tell me what else you may need to carry this into the main tree.

TIA

------------------------------------------------------------------------

[2007-02-28 11:38:27] fjortiz at comunet dot es

Description:
------------
when converting a UTF-8 encoded, multibyte string (Russian for
example), to a COM string, a wrong number of bytes are allocated, thus
creating the COM string with junk bytes at the end.

For example, when I pass my COM-based ADODB driver a 5-letter word in
Russian, I get at destination a 10 (5*2) characters string, the first 5
are the right Russian chars and the rest 5 are junk characters.

This was also explained for 4.4.2 in bug #37899


Actual result:
--------------
this is solved patching two files:
\ext\com_dotnet\com_variant.c, function php_com_variant_from_zval, line
156:

156,157c156
<                       V_BSTR(v) = SysAllocString((char*)olestring);
---
>                       V_BSTR(v) = SysAllocStringByteLen((char*)olestring, 
> Z_STRLEN_P(z)
* sizeof(OLECHAR));

\ext\com_dotnet\com_olechar.c, function php_com_string_to_olestring:

37d36
<       uint unicode_strlen;
39,40c38,44
<       unicode_strlen = MultiByteToWideChar(codepage, (codepage == CP_UTF8
?
<               0 : MB_PRECOMPOSED | MB_ERR_INVALID_CHARS), string, -1, NULL, 
0);
---
>       if (string_len == -1) {
>               /* determine required length for the buffer (includes NUL
terminator) */
>               string_len = MultiByteToWideChar(codepage, flags, string, -1, 
> NULL,
0);
>       } else {
>               /* allow room for NUL terminator */
>               string_len++;
>       }
42,44c46,48
<       if (unicode_strlen > 0) {
<               olestring = (OLECHAR*)safe_emalloc(sizeof(OLECHAR), 
unicode_strlen,
0);
<               ok = MultiByteToWideChar(codepage, flags, string, -1, olestring,
unicode_srlen);
---
>       if (strlen > 0) {
>               olestring = (OLECHAR*)safe_emalloc(sizeof(OLECHAR), string_len,
0);
>               ok = MultiByteToWideChar(codepage, flags, string, string_len,
olestring, string_len);




------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=40664&edit=1

Reply via email to