-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Fix GH-17772: imagepalettetotruecolor segfault on invalid truecolor p… #17777
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
Ugh, that's ugly, since it only affects bundled libgd which uses ZendMM; there appear to be no issues with external libgd (which doesn't heed memory_limit anyway). So it's not likely that we can have a fix being applied upstream, but further down the road some sync might get rid of our fix (should probably add a comment, that Possibly even worse, if upstream ever implements custom allocators (libgd/libgd#335), The general problem I'm seeing here is that libgd never came around to actually implement a contiguous buffer for the pixels (although that is planned for many, many years), so you would have a single allocation upfront, instead of allocating an individual buffer for each row. |
imagepalettetotruecolor($im); | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d |
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.
Since that will only happen with bundled libgd, the test should be skipped if !GD_BUNDLED
.
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.
Besides the nits below, this looks good to me.
@@ -3108,7 +3108,7 @@ int gdImagePaletteToTrueColor(gdImagePtr src) | |||
const unsigned int sy = gdImageSY(src); | |||
const unsigned int sx = gdImageSX(src); | |||
|
|||
src->tpixels = (int **) gdMalloc(sizeof(int *) * sy); | |||
src->tpixels = (int **) gdCalloc(sizeof(int *), sy); |
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.
Please add a comment that this is an intended change, so it won't be inadvertently dropped when syncing with upstream.
ext/gd/tests/gh17772.phpt
Outdated
YuanchengJiang | ||
--SKIPIF-- | ||
<?php | ||
if (!GD_BUNDLED) die("skip requires bundled GD library\n"); |
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 that trailing \n
is superfluous at best.
if (!GD_BUNDLED) die("skip requires bundled GD library\n"); | |
if (!GD_BUNDLED) die("skip requires bundled GD library"); |
…ixel.