Skip to content

Commit

Permalink
Fix some static analysis minor defects (#2569)
Browse files Browse the repository at this point in the history
fix comparison of uint64_t with SIZE_MAX for platforms where uint64_t and size_t are different
  • Loading branch information
vrabaud authored Jan 22, 2025
1 parent 2985845 commit 54e94f5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -1125,9 +1125,11 @@ static avifResult avifDecoderItemMaxExtent(const avifDecoderItem * item, const a

outExtent->offset = minOffset;
const uint64_t extentLength = maxOffset - minOffset;
#if UINT64_MAX > SIZE_MAX
if (extentLength > SIZE_MAX) {
return AVIF_RESULT_BMFF_PARSE_FAILED;
}
#endif
outExtent->size = (size_t)extentLength;
return AVIF_RESULT_OK;
}
Expand Down Expand Up @@ -1952,10 +1954,12 @@ static avifResult avifParseItemLocationBox(avifMeta * meta, const uint8_t * raw,
}
uint64_t offset = baseOffset + extentOffset;
extent->offset = offset;
#if UINT64_MAX > SIZE_MAX
if (extentLength > SIZE_MAX) {
avifDiagnosticsPrintf(diag, "Item ID [%u] contains an extent length which overflows: [%" PRIu64 "]", itemID, extentLength);
return AVIF_RESULT_BMFF_PARSE_FAILED;
}
#endif
extent->size = (size_t)extentLength;
if (extent->size > SIZE_MAX - item->size) {
avifDiagnosticsPrintf(diag,
Expand Down Expand Up @@ -4794,9 +4798,11 @@ static avifResult avifExtentMerge(avifExtent * dst, const avifExtent * src)
const uint64_t maxExtent2 = src->offset + src->size;
dst->offset = AVIF_MIN(minExtent1, minExtent2);
const uint64_t extentLength = AVIF_MAX(maxExtent1, maxExtent2) - dst->offset;
#if UINT64_MAX > SIZE_MAX
if (extentLength > SIZE_MAX) {
return AVIF_RESULT_BMFF_PARSE_FAILED;
}
#endif
dst->size = (size_t)extentLength;
return AVIF_RESULT_OK;
}
Expand Down Expand Up @@ -4866,9 +4872,11 @@ static avifResult avifDecoderPrepareSample(avifDecoder * decoder, avifDecodeSamp
avifDecoderItem * item;
AVIF_CHECKRES(avifMetaFindOrCreateItem(decoder->data->meta, sample->itemID, &item));
avifROData itemContents;
#if UINT64_MAX > SIZE_MAX
if (sample->offset > SIZE_MAX) {
return AVIF_RESULT_BMFF_PARSE_FAILED;
}
#endif
size_t offset = (size_t)sample->offset;
avifResult readResult = avifDecoderItemRead(item, decoder->io, &itemContents, offset, bytesToRead, &decoder->diag);
if (readResult != AVIF_RESULT_OK) {
Expand Down

0 comments on commit 54e94f5

Please sign in to comment.