[Mono-bugs] [Bug 339530] [PATCH] BSTR convertion doesn't roundtrip

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu May 22 19:10:28 EDT 2008


User tom_hindle at sil.org added comment

tom hindle <tom_hindle at sil.org> changed:

           What    |Removed                                         |Added
                 CC|                                                |tom_hindle at sil.org
             Status|RESOLVED                                        |REOPENED
         Resolution|FIXED                                           |

--- Comment #4 from tom hindle <tom_hindle at sil.org>  2008-05-22 17:10:27 MST ---
This bug fix seems to have been lost.

in functions
mono_string_from_bstr and mono_string_to_bstr in mono/metadata/marshal.c

BSTR's marshaled from string's now incorrectly contain max 'character' length
and not byte length in the 4 bytes preceding the start of the BSTR string data.

the Diff for /trunk/mono/mono/metadata/marshal.c between version 89012 and

seems to suggest that this change possibly got lost when  
'if (com_provider == MONO_COM_DEFAULT) {' stuff was added.

in mono_string_to_bstr:
* ((guint32 *) ret) = slen;                svn number 103314

* ((guint32 *) ret) = slen * 2;            svn number 89012
in mono_string_from_bstr

in the older mono_string_to_bstr marshal.c(89012) slen is correctly multiplied
by 2 to store the byte length.

in mono_string_from_bstr:
return mono_string_new_utf16 (mono_domain_get (), bstr, *(guint32 *)((char
*)bstr - 4));             svn number 103314

return mono_string_new_utf16 (mono_domain_get (), bstr, *(guint32 *)((char
*)bstr - 4) / 2);         svn number 89012

in the older mono_string_from_bstr marshal.c(89012) the byte length is
correctly divided by to give the max number of UTF16 'characters'

This incorrectly constructed BSTR can cause native objects, which perform
operations on BSTR marshaled to them from mono, to only use a maximum of half
the string length.
This occurs if the native objects use the BSTR explicit length rather than the
reading to the BSTR NULL terminator.

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the mono-bugs mailing list