Skip to content

Fix GH-16957: Assertion failure in array_shift with self-referencing array #16970

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

nielsdos
Copy link
Member

We have an RC1 violation because we're immediately dereferencing and copying the resulting array in the test case. Instead, transfer the lifetime using ZVAL_COPY_VALUE and unwrap only after the internal iterator is reset.

Targeting 8.3 because it's an unlikely bug to hit and 8.2 is almost EOL.

…ng array

We have an RC1 violation because we're immediately dereferencing and
copying the resulting array in the test case. Instead, transfer the
lifetime using ZVAL_COPY_VALUE and unwrap only after the internal
iterator is reset.
@nielsdos nielsdos requested a review from bukka as a code owner November 27, 2024 19:31
@nielsdos nielsdos linked an issue Nov 27, 2024 that may be closed by this pull request
@bukka bukka requested a review from iluuu1994 November 27, 2024 22:14
Copy link
Member

@bukka bukka left a comment

Choose a reason for hiding this comment

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

It looks good to me but adding also Ilija as it's kind of more engine related...

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

Looks correct, thank you!

@@ -3513,7 +3513,8 @@ PHP_FUNCTION(array_shift)
}
idx++;
}
RETVAL_COPY_DEREF(val);
ZVAL_COPY_VALUE(return_value, val);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: RETVAL_COPY_VALUE()

@@ -3567,7 +3568,8 @@ PHP_FUNCTION(array_shift)
}
idx++;
}
RETVAL_COPY_DEREF(val);
ZVAL_COPY_VALUE(return_value, val);
Copy link
Member

Choose a reason for hiding this comment

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

Same here

@nielsdos nielsdos closed this in f1fc4e8 Nov 29, 2024
charmitro pushed a commit to wasix-org/php that referenced this pull request Mar 13, 2025
…ng array

We have an RC1 violation because we're immediately dereferencing and
copying the resulting array in the test case. Instead, transfer the
lifetime using RETVAL_COPY_VALUE and unwrap only after the internal
iterator is reset.

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

Assertion failure in array_shift with self-referencing array
3 participants