jpeg loader: Limit memory consumption
authorMatthias Clasen <mclasen@redhat.com>
Wed, 10 Aug 2022 17:25:17 +0000 (13:25 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 10 Aug 2022 17:25:17 +0000 (13:25 -0400)
This will prevent stupid oom situations with pathological
jpeg files, without affecting our ability to load reasonable
images.

gdk/loaders/gdkjpeg.c

index 8f7e422f0c0528ecaf3739ed731d19a20162f9ef..a2467cc286bdb99c09b61260e428574da63a565a 100644 (file)
@@ -161,6 +161,8 @@ gdk_load_jpeg (GBytes  *input_bytes,
 
   jpeg_create_decompress (&info);
 
+  info.mem->max_memory_to_use = 100 * 1024 * 1024;
+
   jpeg_mem_src (&info,
                 g_bytes_get_data (input_bytes, NULL),
                 g_bytes_get_size (input_bytes));
@@ -272,6 +274,7 @@ gdk_save_jpeg (GdkTexture *texture)
 
   info.err = jpeg_std_error (&err);
   jpeg_create_compress (&info);
+
   info.image_width = width;
   info.image_height = height;
   info.input_components = 3;
@@ -280,6 +283,8 @@ gdk_save_jpeg (GdkTexture *texture)
   jpeg_set_defaults (&info);
   jpeg_set_quality (&info, 75, TRUE);
 
+  info.mem->max_memory_to_use = 100 * 1024 * 1024;
+
   jpeg_mem_dest (&info, &data, &size);
 
   memtex = gdk_memory_texture_from_texture (texture,