Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions src/cgif_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ static int LZW_GenerateStream(LZWResult* pResult, const uint32_t numPixel, const
// where N = max dictionary resets = numPixel / (MAX_DICT_LEN - initDictLen - 2)
entriesPerCycle = MAX_DICT_LEN - initDictLen - 2; // maximum added number of dictionary entries per cycle: -2 to account for start and end code
maxResets = numPixel / entriesPerCycle;
// check for integer overflow in malloc
if (numPixel > (SIZE_MAX / sizeof(uint16_t) - 2 - maxResets)) {
r = CGIF_EALLOC;
goto LZWGENERATE_Cleanup;
}
pContext->pLZWData = malloc(sizeof(uint16_t) * ((size_t)numPixel + 2 + maxResets));
if(pContext->pLZWData == NULL) {
r = CGIF_EALLOC;
Expand Down
5 changes: 5 additions & 0 deletions src/cgif_rgb.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@ static int quantize_and_dither(colHashTable* colhash, const uint8_t* pImageDataR
if(root == NULL) {
return -1;
}
// check for integer overflow in malloc
if (numPixel > (SIZE_MAX / (fmtChan * sizeof(float)))) {
free_decision_tree(root);
return -1;
}
float* pImageDataRGBfloat = malloc(fmtChan * numPixel * sizeof(float)); // TBD fmtChan + only when hasAlpha
if(pImageDataRGBfloat == NULL) {
free_decision_tree(root);
Expand Down
Loading