From b659038e4296534c2e068de9bce8d9e17fbe58b4 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 9 Aug 2022 16:10:40 +0100 Subject: jpeg: Limit the memory size when loading image data Specially crafted JPEG images may lead to a crash when their size is too large; in the most benign of cases, the OS might terminate the process after it tries to allocate all the memory in the world. We can tell libjpeg to limit the size of the memory pool when loading, to avoid this kind of result. For the time being, 100 MB seems like a good threshold. Original patch by: Sam Ezeh Fixes: #205 --- gdk-pixbuf/io-jpeg.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gdk-pixbuf') diff --git a/gdk-pixbuf/io-jpeg.c b/gdk-pixbuf/io-jpeg.c index 48b163755..22f4174fe 100644 --- a/gdk-pixbuf/io-jpeg.c +++ b/gdk-pixbuf/io-jpeg.c @@ -1090,6 +1090,8 @@ gdk_pixbuf__jpeg_image_load_increment (gpointer data, jpeg_save_markers (cinfo, JPEG_COM, 0xffff); rc = jpeg_read_header (cinfo, TRUE); context->src_initialized = TRUE; + + cinfo->mem->max_memory_to_use = 100 * 1024 * 1024; if (rc == JPEG_SUSPENDED) continue; -- cgit v1.2.1