Skip to content

Fix oss-fuzz report triggered by GH-15712 commit. #15915

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

Closed
wants to merge 3 commits into from

Conversation

devnexen
Copy link
Member

It triggered allocation overflow which, even fixed, in turn gives memory leak on 32 bits but the allocator relies on signed integers so instead of changing j type we exit if an overflow during the buffer increase is going to happen.

It triggered allocation overflow which, even fixed, in turn gives memory
leak on 32 bits but the allocator relies on signed integers so instead
of changing `j` type we exit if an overflow during the buffer increase
is going to happen.
@cmb69
Copy link
Member

cmb69 commented Sep 16, 2024

Maybe we should constrain precision (and related) in the first place (and give users some hint):

php-src/main/main.c

Lines 289 to 298 in c7397f5

static PHP_INI_MH(OnSetPrecision)
{
zend_long i = ZEND_ATOL(ZSTR_VAL(new_value));
if (i >= -1) {
EG(precision) = i;
return SUCCESS;
} else {
return FAILURE;
}
}

I mean, even precision=100 makes no sense; you just get some made-up garbage (https://3v4l.org/eQinL).

@devnexen
Copy link
Member Author

devnexen commented Sep 16, 2024

for sure, but I was thinking it s behavior change, precision never was limited and I am targeting a stable branch. Thought it was more appropriate for master.

@cmb69
Copy link
Member

cmb69 commented Sep 16, 2024

Thought it was more appropriate for master.

Oh, absolutely. :)

@devnexen devnexen requested a review from cmb69 November 2, 2024 04:52
Copy link
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

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

If the loop is terminated because j > (INT_MAX >> 1), isn't there the risk of a buffer overflow in the following? I think in this case we would need to bail out (exception or even a fatal error).

And if we bail out, we could also check whether i exceeds the threshold before even entering the loop.

And from there we can even move the check up the stack; likely zend_dtoa() should not accept very large ndigits.

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

Copy link
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

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

Thank you! That should fix it.

@devnexen devnexen closed this in e74e66e Nov 7, 2024
@cmb69
Copy link
Member

cmb69 commented Nov 8, 2024

Oh, I've overlooked that the test leaks now. We could mark it as --XFAIL--, or silently clamp the value to its allowed maximum (I don't think anybody will notice :).

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