Skip to content

Commit c6b6a7a

Browse files
committed
avoid overflow by promoting grid multiplications to uint64_t
1 parent eebc2c1 commit c6b6a7a

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/read.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,8 +1739,9 @@ static avifResult avifDecoderDataAllocateImagePlanes(const avifDecoderData * dat
17391739
// The tiled input images shall completely "cover" the reconstructed image grid canvas, ...
17401740

17411741
// Check for integer overflow before performing multiplications
1742-
if ((tile->image->width > 0 && grid->columns > UINT32_MAX / tile->image->width) ||
1743-
(tile->image->height > 0 && grid->rows > UINT32_MAX / tile->image->height)) {
1742+
if (((uint64_t)tile->image->width * grid->columns < grid->outputWidth) ||
1743+
((uint64_t)tile->image->height * grid->rows < grid->outputHeight)) {
1744+
17441745
avifDiagnosticsPrintf(data->diag,
17451746
"Grid image dimensions would cause integer overflow");
17461747
return AVIF_RESULT_INVALID_IMAGE_GRID;
@@ -1760,8 +1761,8 @@ static avifResult avifDecoderDataAllocateImagePlanes(const avifDecoderData * dat
17601761
return AVIF_RESULT_INVALID_IMAGE_GRID;
17611762
}
17621763

1763-
if (((tile->image->width * (grid->columns - 1)) >= grid->outputWidth) ||
1764-
((tile->image->height * (grid->rows - 1)) >= grid->outputHeight)) {
1764+
if (((uint64_t)tile->image->width * (grid->columns - 1) >= grid->outputWidth) ||
1765+
((uint64_t)tile->image->height * (grid->rows - 1) >= grid->outputHeight)) {
17651766
avifDiagnosticsPrintf(data->diag,
17661767
"Grid image tiles in the rightmost column and bottommost row do not overlap the reconstructed image grid canvas. See MIAF (ISO/IEC 23000-22:2019), Section 7.3.11.4.2, Figure 2");
17671768
return AVIF_RESULT_INVALID_IMAGE_GRID;

0 commit comments

Comments
 (0)