Skip to content
Permalink
Browse files Browse the repository at this point in the history
Do not realloc array if new raster size is 0.
if realloc() is called with 0 size it may return NULL and this will be incorrectly handled
as not enough memory and (also) rasterBits will be freed by realloc but we will not update
it.
  • Loading branch information
os97673 authored and koral-- committed Sep 8, 2019
1 parent 41c29a0 commit cc5b4f8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions android-gif-drawable/src/main/c/decoding.c
Expand Up @@ -56,9 +56,15 @@ void DDGifSlurp(GifInfo *info, bool decode, bool exitAfterFrame) {
}

if (decode) {
int_fast32_t widthOverflow = gifFilePtr->Image.Width - info->originalWidth;
int_fast32_t heightOverflow = gifFilePtr->Image.Height - info->originalHeight;
const uint_fast32_t newRasterSize = gifFilePtr->Image.Width * gifFilePtr->Image.Height;
if (newRasterSize == 0) {
free(info->rasterBits);
info->rasterBits = NULL;
info->rasterSize = newRasterSize;
return;
}
const int_fast32_t widthOverflow = gifFilePtr->Image.Width - info->originalWidth;
const int_fast32_t heightOverflow = gifFilePtr->Image.Height - info->originalHeight;
if (newRasterSize > info->rasterSize || widthOverflow > 0 || heightOverflow > 0) {
void *tmpRasterBits = reallocarray(info->rasterBits, newRasterSize, sizeof(GifPixelType));
if (tmpRasterBits == NULL) {
Expand Down

0 comments on commit cc5b4f8

Please sign in to comment.