Skip to content

Remove broken check in var_unserializer #13852

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

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions ext/standard/var_unserializer.re
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,6 @@ static zend_string *unserialize_str(const unsigned char **p, size_t len, size_t
zend_string *str = zend_string_safe_alloc(1, len, 0, 0);
unsigned char *end = *(unsigned char **)p+maxlen;

if (end < *p) {
zend_string_efree(str);
return NULL;
}
Comment on lines -329 to -332
Copy link
Member

@arnaud-lb arnaud-lb Apr 2, 2024

Choose a reason for hiding this comment

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

This may not break anything that wasn't already broken because this was optimized out by the compiler, but I would prefer if we fixed this check instead of simply removing it

Copy link
Member Author

@nielsdos nielsdos Apr 2, 2024

Choose a reason for hiding this comment

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

The intention of the check seems to be to see if maxlen wraps around the address space.
I don't think that's possible, given that maxlen = max - YYCURSOR; and the fact that max is the pointer to the end of the input string.
So I'm not sure what you want me to replace this check with?

Copy link
Member

Choose a reason for hiding this comment

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

You are right. I was blindly assuming that maxlen was possibly user-controlled. Looking at the history this check made more sense at some point, but now it can be removed.

Copy link
Member

Choose a reason for hiding this comment

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

This is out of scope, but we could pass max directly to this function, maybe via UNSERIALIZE_PASSTHRU/UNSERIALIZE_PARAMETER.


for (i = 0; i < len; i++) {
if (*p >= end) {
zend_string_efree(str);
Expand Down