-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fixes #73373 (deflate_add does not verify that output was not truncated) #2172
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
Conversation
/* more output buffer space needed; realloc and try again */ | ||
/* adding 64 more bytes solved every issue I have seen */ | ||
/* the + 1 is for the string terminator added below */ | ||
out = zend_string_realloc(out, ZSTR_LEN(out) + 64 + 1, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this +1. I don't know about zlib, so just an observation.
- There wasn't a +1 before. Why is it needed now?
- Performing this +1 inside the loop will add an extra 1 on each iteration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am pretty sure though the compiler will elide 64 + 1 to + 65 ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the point was that zend_string_realloc accepts a length. The extra byte for the terminator is added implicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. Makes sense, though it doesn't make any difference. I already pushed it now; doesn't really matter.
/* more output buffer space needed; realloc and try again */ | ||
/* adding 64 more bytes solved every issue I have seen */ | ||
/* the + 1 is for the string terminator added below */ | ||
out = zend_string_realloc(out, ZSTR_LEN(out) + 64 + 1, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should check for overflow here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overflow? Why? When an addition of 64 will overflow, we already will long have had an out of memory before...
@bwoebi IIRC you worked on this, can you take a look? |
https://bugs.php.net/bug.php?id=73373