Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Limit JPEG loader to the `Image::MAX_PIXELS` before decoding.

Pāvels Nadtočajevs00a5bede441a
diff --git a/modules/jpg/image_loader_libjpeg_turbo.cpp b/modules/jpg/image_loader_libjpeg_turbo.cpp
index be3ea549c1c..b44bc7473cd 100644
--- a/modules/jpg/image_loader_libjpeg_turbo.cpp
+++ b/modules/jpg/image_loader_libjpeg_turbo.cpp
@@ -47,6 +47,12 @@ Error jpeg_turbo_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer,
const unsigned int height = tj3Get(tj_instance, TJPARAM_JPEGHEIGHT);
const TJCS colorspace = (TJCS)tj3Get(tj_instance, TJPARAM_COLORSPACE);
+ if (width * height > Image::MAX_PIXELS) {
+ tj3Destroy(tj_instance);
+ ERR_FAIL_V_MSG(ERR_UNAVAILABLE,
+ vformat("Too many pixels for Image. Maximum is %d pixels.", Image::MAX_PIXELS));
+ }
+
if (tj3Get(tj_instance, TJPARAM_PRECISION) > 8) {
// TODO: Proceed anyway and convert to rgb8?
ERR_PRINT("JPEGTurbo: JPEG files with precision > 8 are not currently supported.");