Commit bb6f3fcf for libheif
commit bb6f3fcf55ada208b2f8bec03d6d671a0fa90c13
Author: Dirk Farin <dirk.farin@gmail.com>
Date: Sat Nov 29 22:19:08 2025 +0100
change type if HeifPixelImage::ImagePlane::m_stride to size_t to prevent overflows in computations (#1631)
diff --git a/libheif/pixelimage.cc b/libheif/pixelimage.cc
index 84a8dd73..8aa104f2 100644
--- a/libheif/pixelimage.cc
+++ b/libheif/pixelimage.cc
@@ -1086,10 +1086,10 @@ void HeifPixelImage::ImagePlane::rotate_ccw(int angle_degrees,
uint32_t w = m_width;
uint32_t h = m_height;
- uint32_t in_stride = stride / uint32_t(sizeof(T));
+ size_t in_stride = stride / sizeof(T);
const T* in_data = static_cast<const T*>(mem);
- uint32_t out_stride = out_plane.stride / uint32_t(sizeof(T));
+ size_t out_stride = out_plane.stride / sizeof(T);
T* out_data = static_cast<T*>(out_plane.mem);
if (angle_degrees == 270) {
@@ -1297,10 +1297,10 @@ Result<std::shared_ptr<HeifPixelImage>> HeifPixelImage::crop(uint32_t left, uint
void HeifPixelImage::ImagePlane::crop(uint32_t left, uint32_t right, uint32_t top, uint32_t bottom,
int bytes_per_pixel, ImagePlane& out_plane) const
{
- uint32_t in_stride = stride;
+ size_t in_stride = stride;
auto* in_data = static_cast<const uint8_t*>(mem);
- uint32_t out_stride = out_plane.stride;
+ size_t out_stride = out_plane.stride;
auto* out_data = static_cast<uint8_t*>(out_plane.mem);
for (uint32_t y = top; y <= bottom; y++) {
diff --git a/libheif/pixelimage.h b/libheif/pixelimage.h
index 41e636fb..7206ca6f 100644
--- a/libheif/pixelimage.h
+++ b/libheif/pixelimage.h
@@ -369,7 +369,7 @@ private:
void* mem = nullptr; // aligned memory start
uint8_t* allocated_mem = nullptr; // unaligned memory we allocated
size_t allocation_size = 0;
- uint32_t stride = 0; // bytes per line
+ size_t stride = 0; // bytes per line
int get_bytes_per_pixel() const;