-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibheif.patch
More file actions
68 lines (62 loc) · 2.22 KB
/
libheif.patch
File metadata and controls
68 lines (62 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
diff --git a/libheif/pixelimage.cc b/libheif/pixelimage.cc
index 04e81fe..5e95b23 100644
--- a/libheif/pixelimage.cc
+++ b/libheif/pixelimage.cc
@@ -262,43 +262,43 @@ Error HeifPixelImage::ImagePlane::alloc(uint32_t width, uint32_t height, heif_ch
assert(alignment>=1);
+ size_t allocation_size = static_cast<size_t>(m_mem_height) * stride + alignment - 1;
+
if (limits &&
limits->max_memory_block_size &&
(limits->max_memory_block_size < alignment - 1U ||
(limits->max_memory_block_size - (alignment - 1U)) / stride < m_mem_height)) {
std::stringstream sstr;
- sstr << "Allocating " << static_cast<size_t>(m_mem_height) * stride + alignment - 1 << " bytes exceeds the security limit of "
+ sstr << "Allocating " << allocation_size << " bytes exceeds the security limit of "
<< limits->max_memory_block_size << " bytes";
return {heif_error_Memory_allocation_error,
heif_suberror_Security_limit_exceeded,
sstr.str()};
}
-
- try {
- 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
-
- auto mem_start_addr = (uint64_t) mem_8;
- auto mem_start_offset = (mem_start_addr & (alignment - 1U));
- if (mem_start_offset != 0) {
- mem_8 += alignment - mem_start_offset;
- }
-
- mem = mem_8;
-
- return Error::Ok;
- }
- catch (const std::bad_alloc& excpt) {
+ allocated_mem = new (std::nothrow) uint8_t[allocation_size];
+ if (allocated_mem == nullptr) {
std::stringstream sstr;
- sstr << "Allocating " << static_cast<size_t>(m_mem_height) * stride + alignment - 1 << " bytes failed";
+ sstr << "Allocating " << allocation_size << " bytes failed";
return {heif_error_Memory_allocation_error,
heif_suberror_Unspecified,
sstr.str()};
}
+
+ uint8_t* mem_8 = allocated_mem;
+
+ // shift beginning of image data to aligned memory position
+
+ auto mem_start_addr = (uint64_t) mem_8;
+ auto mem_start_offset = (mem_start_addr & (alignment - 1U));
+ if (mem_start_offset != 0) {
+ mem_8 += alignment - mem_start_offset;
+ }
+
+ mem = mem_8;
+
+ return Error::Ok;
}