Skip to content

Conversation

nielsdos
Copy link
Member

A bunch of different issues:

  1. The referenced value is copied without incrementing the refcount.
    The reason the refcount isn't incremented is because otherwise
    the array modifications would violate the RC1 constraints.
    Solve this by copying the reference itself instead and always
    read the referenced value.
  2. No type checks on the array data, so malicious scripts could
    cause type confusion bugs.
  3. Potential overflow when the arrays resize and we access ctag.

@nielsdos nielsdos linked an issue Dec 17, 2024 that may be closed by this pull request
@nielsdos
Copy link
Member Author

This extension also needs a bit of cleanup tbh...

@nielsdos nielsdos marked this pull request as ready for review December 19, 2024 19:21
A bunch of different issues:
1) The referenced value is copied without incrementing the refcount.
   The reason the refcount isn't incremented is because otherwise
   the array modifications would violate the RC1 constraints.
   Solve this by copying the reference itself instead and always
   read the referenced value.
2) No type checks on the array data, so malicious scripts could
   cause type confusion bugs.
3) Potential overflow when the arrays resize and we access ctag.
@nielsdos nielsdos requested a review from devnexen December 27, 2024 13:05

xdata = zend_try_array_init(xdata);
if (!xdata) {
if (!zend_try_array_init(xdata)) {
Copy link
Member

Choose a reason for hiding this comment

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

not entirely certain about these two changes, is it a cleanup thing you re doing here ?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not cleanup, we need the original value of xdata.
xdata is now a reference, but if the return value of zend_try_array_init were used then it would be the array that xdata references to. We need to hold on to the reference, we can't hold on to the array because that would break the RC1 constraint of the array and would also make it impossible to separate it.

Copy link
Member

Choose a reason for hiding this comment

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

ah ok makes a lot more sense.

@nielsdos nielsdos closed this in b621b3a Dec 27, 2024
charmitro pushed a commit to wasix-org/php that referenced this pull request Mar 13, 2025
A bunch of different issues:
1) The referenced value is copied without incrementing the refcount.
   The reason the refcount isn't incremented is because otherwise
   the array modifications would violate the RC1 constraints.
   Solve this by copying the reference itself instead and always
   read the referenced value.
2) No type checks on the array data, so malicious scripts could
   cause type confusion bugs.
3) Potential overflow when the arrays resize and we access ctag.

Closes phpGH-17205.
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.

unreachable program point in zend_hash

2 participants