Skip to content
Closed
Changes from 2 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
15 changes: 12 additions & 3 deletions Zend/zend_strtod.c
Original file line number Diff line number Diff line change
Expand Up @@ -3613,13 +3613,22 @@ rv_alloc(i) int i;
rv_alloc(int i)
#endif
{

int k, *r;
size_t j, rem;

rem = sizeof(Bigint) - sizeof(ULong) - sizeof(int);

size_t j = sizeof(ULong);

j = sizeof(ULong);
if (i > (INT_MAX - rem))
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 this line should be

Suggested change
if (i > (INT_MAX - rem))
if (i > ((INT_MAX >> 2) + rem))

Then the other overflow check should be superfluous.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, and I think reverting the changes from #15715 could also be appropriate, since j should never exceed INT_MAX (actually, it must always be less than 0x40000000).

zend_error_noreturn(E_ERROR, "rv_alloc() allocation overflow %d", i);
for(k = 0;
sizeof(Bigint) - sizeof(ULong) - sizeof(int) + j <= (size_t)i;
j <<= 1)
j <= (INT_MAX >> 1) && rem + j <= (size_t)i; j <<= 1)
k++;
if (j > (INT_MAX >> 1))
zend_error_noreturn(E_ERROR, "rv_alloc() computation overflow " ZEND_LONG_FMT, j);

r = (int*)Balloc(k);
*r = k;
return
Expand Down
Loading