Skip to content

Fix FFI::string() reading out of bounds for a negative size - #25731

Closed
marc-mabe wants to merge 1 commit into
php:PHP-8.4from
marc-mabe:fix/ffi-string-negative-size
Closed

marc-mabe wants to merge 1 commit into
php:PHP-8.4from
marc-mabe:fix/ffi-string-negative-size

Conversation

@marc-mabe

Copy link
Copy Markdown
Contributor

FFI::string() passed a negative size on to the string allocation, where it wrapped around to a small allocation that was then filled with nearly SIZE_MAX bytes read from the pointer. For arrays, a negative size was rejected by the comparison with the array size only because that comparison happens to be unsigned.

Reject a negative size with a ValueError, for pointers and arrays alike.

FFI::string() passed a negative size on to the string allocation, where
it wrapped around to a small allocation that was then filled with
nearly SIZE_MAX bytes read from the pointer. For arrays, a negative size was
rejected by the comparison with the array size only because that
comparison happens to be unsigned.

Reject a negative size with a ValueError, for pointers and arrays alike.

@ndossche ndossche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks

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