|
7 | 7 | #include <cstring> |
8 | 8 |
|
9 | 9 | #include "flutter/fml/logging.h" |
| 10 | +#include "flutter/fml/safe_math.h" |
10 | 11 | #include "third_party/skia/include/codec/SkCodec.h" |
11 | 12 | #include "third_party/skia/include/codec/SkCodecAnimation.h" |
12 | 13 | #include "third_party/skia/include/core/SkAlphaType.h" |
@@ -91,10 +92,26 @@ bool APNGImageGenerator::GetPixels(const SkImageInfo& info, |
91 | 92 |
|
92 | 93 | APNGImage& frame = images_[image_index]; |
93 | 94 | SkImageInfo frame_info = frame.codec->getInfo(); |
94 | | - auto frame_row_bytes = frame_info.bytesPerPixel() * frame_info.width(); |
| 95 | + |
| 96 | + fml::SafeMath safe; |
| 97 | + size_t frame_row_bytes = |
| 98 | + safe.mul(frame_info.bytesPerPixel(), frame_info.width()); |
| 99 | + if (safe.overflow_detected()) { |
| 100 | + FML_DLOG(ERROR) << "Failed to decode image at index " << image_index |
| 101 | + << " (frame index: " << frame_index |
| 102 | + << ") of APNG due to frame row bytes overflow."; |
| 103 | + return false; |
| 104 | + } |
95 | 105 |
|
96 | 106 | if (frame.pixels.empty()) { |
97 | | - frame.pixels.resize(frame_row_bytes * frame_info.height()); |
| 107 | + size_t pixels_bytes = safe.mul(frame_row_bytes, frame_info.height()); |
| 108 | + if (safe.overflow_detected()) { |
| 109 | + FML_DLOG(ERROR) << "Failed to decode image at index " << image_index |
| 110 | + << " (frame index: " << frame_index |
| 111 | + << ") of APNG due to pixel buffer size overflow."; |
| 112 | + return false; |
| 113 | + } |
| 114 | + frame.pixels.resize(pixels_bytes); |
98 | 115 | SkCodec::Result result = frame.codec->getPixels( |
99 | 116 | frame.codec->getInfo(), frame.pixels.data(), frame_row_bytes); |
100 | 117 | if (result != SkCodec::kSuccess) { |
|
0 commit comments