|
4 | 4 | #include "avif/internal.h" |
5 | 5 | #include <assert.h> |
6 | 6 | #include <float.h> |
| 7 | +#include <limits.h> |
7 | 8 | #include <math.h> |
8 | 9 | #include <string.h> |
9 | 10 |
|
@@ -559,11 +560,11 @@ avifResult avifRGBImageComputeGainMap(const avifRGBImage * baseRgbImage, |
559 | 560 | avifResult res = AVIF_RESULT_OK; |
560 | 561 | // --- After this point, the function should exit with 'goto cleanup' to free allocated resources. |
561 | 562 |
|
| 563 | + AVIF_CHECKERR(width == 0 || height <= (SIZE_MAX / width), AVIF_RESULT_INVALID_ARGUMENT); |
562 | 564 | const size_t numPixels = (size_t)width * height; |
563 | | - if (numPixels > SIZE_MAX / sizeof(float)) { |
564 | | - res = AVIF_RESULT_INVALID_ARGUMENT; |
565 | | - goto cleanup; |
566 | | - } |
| 565 | + AVIF_CHECKERR(numPixels <= (SIZE_MAX / sizeof(float)), AVIF_RESULT_INVALID_ARGUMENT); |
| 566 | + // avifFindMinMaxWithoutOutliers() takes numPixels as int. |
| 567 | + AVIF_CHECKERR(numPixels <= INT_MAX, AVIF_RESULT_INVALID_ARGUMENT); |
567 | 568 | const size_t gainMapChannelSize = numPixels * sizeof(float); |
568 | 569 | const avifBool singleChannel = (gainMap->image->yuvFormat == AVIF_PIXEL_FORMAT_YUV400); |
569 | 570 | const int numGainMapChannels = singleChannel ? 1 : 3; |
@@ -725,7 +726,7 @@ avifResult avifRGBImageComputeGainMap(const avifRGBImage * baseRgbImage, |
725 | 726 | float gainMapMinLog2[3] = { 0.0f, 0.0f, 0.0f }; |
726 | 727 | float gainMapMaxLog2[3] = { 0.0f, 0.0f, 0.0f }; |
727 | 728 | for (int c = 0; c < numGainMapChannels; ++c) { |
728 | | - res = avifFindMinMaxWithoutOutliers(gainMapF[c], numPixels, &gainMapMinLog2[c], &gainMapMaxLog2[c]); |
| 729 | + res = avifFindMinMaxWithoutOutliers(gainMapF[c], (int)numPixels, &gainMapMinLog2[c], &gainMapMaxLog2[c]); |
729 | 730 | if (res != AVIF_RESULT_OK) { |
730 | 731 | goto cleanup; |
731 | 732 | } |
|
0 commit comments