Skip to content

Conversation

@cmb69
Copy link
Member

@cmb69 cmb69 commented Jun 25, 2020

A BSTR is similar to a zend_string; it stores the length of the
string just before the actual string, and thus the string may contain
NUL bytes. However, php_com_olestring_to_string() is supposed to
deal with arbitrary OLECHAR*s which may not be BSTRs, so we
introduce php_com_bstr_to_string() and use it for the only case where
we actually have to deal with BSTRs which may contain NUL bytes.

Contrary to php_com_olestring_to_string() we return a zend_string,
so we can save the re-allocation when converting to a zval.

A `BSTR` is similar to a `zend_string`; it stores the length of the
string just before the actual string, and thus the string may contain
NUL bytes.  However, `php_com_olestring_to_string()` is supposed to
deal with arbitrary `OLECHAR*`s which may not be `BSTR`s, so we
introduce `php_com_bstr_to_string()` and use it for the only case where
we actually have to deal with `BSTR`s which may contain NUL bytes.

Contrary to `php_com_olestring_to_string()` we return a `zend_string`,
so we can save the re-allocation when converting to a `zval`.
@cmb69 cmb69 added the Bug label Jun 25, 2020
We have to properly determine the output length of the conversion to
multi byte strings.

We also cater to `php_com_string_to_olestring()` not being binary safe,
with basically the same fix we did for `php_com_olestring_to_string()`.
Instead of allocating a temporary `OLECHAR` buffer, we allocate the
final `BSTR` right away, and do the multibyte conversion into its
buffer.

We also refactor to guard statements for better readability.
@cmb69 cmb69 closed this Jun 29, 2020
@cmb69 cmb69 deleted the cmb/63208 branch June 29, 2020 17:08
@cmb69
Copy link
Member Author

cmb69 commented Jun 29, 2020

Thanks! Applied as a385cfa.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants