Skip to content

Commit

Permalink
limit maximum memory allocation (should fix ClusterFuzz 71389)
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk committed Sep 11, 2024
1 parent 2395082 commit 9483961
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion libheif/pixelimage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "pixelimage.h"
#include "common_utils.h"
#include "security_limits.h"

#include <cassert>
#include <cstring>
Expand Down Expand Up @@ -256,8 +257,12 @@ bool HeifPixelImage::ImagePlane::alloc(uint32_t width, uint32_t height, heif_cha
stride = m_mem_width * bytes_per_pixel;
stride = (stride + alignment - 1U) & ~(alignment - 1U);

if ((MAX_MEMORY_BLOCK_SIZE - (alignment + 1)) / stride < m_mem_height) {
return false;
}

try {
allocated_mem = new uint8_t[m_mem_height * stride + alignment - 1];
allocated_mem = new uint8_t[static_cast<size_t>(m_mem_height) * stride + alignment - 1];
uint8_t* mem_8 = allocated_mem;

// shift beginning of image data to aligned memory position
Expand Down

0 comments on commit 9483961

Please sign in to comment.