Skip to content

Conversation

mbonneau
Copy link
Contributor

@mbonneau mbonneau changed the title Fixes #73373 Fixes #73373 (deflate_add does not verify that output was not truncated) Oct 22, 2016
@smalyshev smalyshev added the Bug label Oct 31, 2016
/* 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);
Copy link
Contributor

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.

  1. There wasn't a +1 before. Why is it needed now?
  2. Performing this +1 inside the loop will add an extra 1 on each iteration.

Copy link
Member

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 ...

Copy link
Member

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.

Copy link
Member

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);
Copy link
Contributor

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.

Copy link
Member

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...

@nikic
Copy link
Member

nikic commented Dec 22, 2016

@bwoebi IIRC you worked on this, can you take a look?

@nikic
Copy link
Member

nikic commented Jan 8, 2017

This has already been merged via 8823b68, the PR just wasn't closed...

Just applied a small additional cleanup: b36f4ac

@nikic nikic closed this Jan 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants