Skip to content

Fix property access of PHP objects wrapped in variant #16331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Oct 9, 2024

First, we fix the long standing issue that property access throws a com_exception ("0x80020003: member not found), because the HRESULT was not properly set after accessing the property.

Next, we fix an issue introduced as of PHP 7.0.0, where the string length for write access had been properly adapted, but the string length for read access had been overlooked.

Then we fix an issue introduced as of PHP 8.0.0, where new HashTables no longer set nNextFreeElement to zero, but to ZEND_LONG_MIN. This doesn't work well with the DISPID lookup, which is a LONG.

Finally we fix a potential double-free due to erroneously destroying the return value of zend_read_property().


Given that this is completely broken as of PHP 8.0.0 at least, and apparently nobody has complained, I think we're good targeting master (we can backport later if necessary).

Note that this doesn't fix calling methods, which is broken since 2005, because DISPATCH_METHOD|DISPATCH_PROPERTYGET is passed as flag, and the latter is always prioritized in disp_invokeex() (what is likely good for regular COM objects).

First, we fix the long standing issue that property access throws a
`com_exception` ("0x80020003: member not found), because the `HRESULT`
was not properly set after accessing the property.

Next, we fix an issue introduced as of PHP 7.0.0, where the string
length for write access had been properly adapted, but the string
length for read access had been overlooked.

Then we fix an issue introduced as of PHP 8.0.0, where new `HashTable`s
no longer set `nNextFreeElement` to zero, but to `ZEND_LONG_MIN`.  This
doesn't work well with the `DISPID` lookup, which is a `LONG`.

Finally we fix a potential double-free due to erroneously destroying
the return value of `zend_read_property()`.
Copy link
Member

@arnaud-lb arnaud-lb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested, but the changes look ok to me apart from the TODO

Comment on lines -308 to +310
zval_ptr_dtor(retval);
// zval_ptr_dtor(retval); // TODO needed for function calls?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I believe this is needed for function calls

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See

Note that this doesn't fix calling methods, which is broken since 2005, because DISPATCH_METHOD|DISPATCH_PROPERTYGET is passed as flag, and the latter is always prioritized in disp_invokeex() (what is likely good for regular COM objects).

I'm planning to fix this in a follow-up PR. Thus I left the comment to not forget about destroying.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I overlooked this. This looks ok to me then

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

Successfully merging this pull request may close these issues.

2 participants