From 11cbea856b88a68074d3f98fc367248eed495460 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 26 Oct 2024 13:45:34 +0200 Subject: [PATCH] HEIF: add casts to size_t to be on the safer size Perhaps not needed, but can't hurt --- frmts/heif/heifdataset.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/frmts/heif/heifdataset.cpp b/frmts/heif/heifdataset.cpp index 819089adb15f..7786b0af1bd7 100644 --- a/frmts/heif/heifdataset.cpp +++ b/frmts/heif/heifdataset.cpp @@ -671,8 +671,11 @@ CPLErr GDALHEIFRasterBand::IReadBlock(int nBlockXOff, int nBlockYOff, { for (int x = 0; x < nBlockXSize; x++) { - size_t srcIndex = y * nStride + x * nBands + nBand - 1; - size_t outIndex = static_cast(y) * nBlockXSize + x; + const size_t srcIndex = static_cast(y) * nStride + + static_cast(x) * nBands + + nBand - 1; + const size_t outIndex = + static_cast(y) * nBlockXSize + x; (static_cast(pImage))[outIndex] = pSrcData[srcIndex]; } } @@ -683,9 +686,11 @@ CPLErr GDALHEIFRasterBand::IReadBlock(int nBlockXOff, int nBlockYOff, { for (int x = 0; x < nBlockXSize; x++) { - size_t srcIndex = static_cast(y) * (nStride / 2) + - x * nBands + nBand - 1; - size_t outIndex = static_cast(y) * nBlockXSize + x; + const size_t srcIndex = static_cast(y) * (nStride / 2) + + static_cast(x) * nBands + + nBand - 1; + const size_t outIndex = + static_cast(y) * nBlockXSize + x; (static_cast(pImage))[outIndex] = (reinterpret_cast(pSrcData))[srcIndex]; } @@ -751,19 +756,19 @@ CPLErr GDALHEIFRasterBand::IReadBlock(int, int nBlockYOff, void *pImage) int nStride = 0; const uint8_t *pSrcData = heif_image_get_plane_readonly( poGDS->m_hImage, heif_channel_interleaved, &nStride); - pSrcData += nBlockYOff * nStride; + pSrcData += static_cast(nBlockYOff) * nStride; if (eDataType == GDT_Byte) { for (int i = 0; i < nBlockXSize; i++) (static_cast(pImage))[i] = - pSrcData[nBand - 1 + i * nBands]; + pSrcData[nBand - 1 + static_cast(i) * nBands]; } else { for (int i = 0; i < nBlockXSize; i++) (static_cast(pImage))[i] = (reinterpret_cast( - pSrcData))[nBand - 1 + i * nBands]; + pSrcData))[nBand - 1 + static_cast(i) * nBands]; } return CE_None;