File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -82,6 +82,16 @@ struct DecodeImage {
8282 const int64_t height = static_cast <int64_t >(CGImageGetHeight (image));
8383 const int64_t channels = 3 ;
8484
85+ // Add dimension limit to prevent decompression bombs
86+ static constexpr int64_t kMaxImageDimension = 16384 ;
87+ static constexpr int64_t kMaxPixelCount = 100 * 1024 * 1024 ; // 100 megapixels
88+ if (width > kMaxImageDimension || height > kMaxImageDimension ||
89+ width * height > kMaxPixelCount ) {
90+ CGImageRelease (image);
91+ return {kOrtxErrorInvalidArgument ,
92+ " [ImageDecoder]: Image dimensions exceed maximum allowed size." };
93+ }
94+
8595 std::vector<int64_t > output_dimensions{height, width, channels};
8696 uint8_t * decoded_image_data = output.Allocate (output_dimensions);
8797
Original file line number Diff line number Diff line change @@ -111,6 +111,15 @@ struct DecodeImage {
111111 const int width = static_cast <int >(uiWidth);
112112 const int channels = 3 ; // Asks for RGB
113113
114+ // Add dimension limit to prevent decompression bombs
115+ static constexpr UINT kMaxImageDimension = 16384 ;
116+ static constexpr uint64_t kMaxPixelCount = 100 * 1024 * 1024 ; // 100 megapixels
117+ if (uiWidth > kMaxImageDimension || uiHeight > kMaxImageDimension ||
118+ static_cast <uint64_t >(uiWidth) * uiHeight > kMaxPixelCount ) {
119+ return {kOrtxErrorInvalidArgument ,
120+ " [ImageDecoder]: Image dimensions exceed maximum allowed size." };
121+ }
122+
114123 // Security: reject CMYK pixel formats (e.g. CMYK JPEGs) before silent conversion.
115124 // WICConvertBitmapSource can silently convert CMYK→RGB, hiding the 4-channel shape from
116125 // downstream consumers that assume 3 channels, enabling heap overflow (CWE-122).
You can’t perform that action at this time.
0 commit comments