Bug 1184009 - Limit image preview sizes. r=acomminos, a=lmandel
authorLee Salzman <lsalzman@mozilla.com>
Tue, 21 Jul 2015 13:16:44 -0400
changeset 291358 9b861360b297f18f62cb9c8dfb576fc9eb507331
parent 291357 34b95d9ef07ef0dc6079d72b9eb40bb4701b9722
child 291359 c0bed95cdc18733613b7650ce206e1b15865bcce
push id5246
push usermozilla@noorenberghe.ca
push dateWed, 09 Sep 2015 21:17:14 +0000
reviewersacomminos, lmandel
bugs1184009
milestone40.0
Bug 1184009 - Limit image preview sizes. r=acomminos, a=lmandel
widget/gtk/nsFilePicker.cpp
--- a/widget/gtk/nsFilePicker.cpp
+++ b/widget/gtk/nsFilePicker.cpp
@@ -96,23 +96,26 @@ UpdateFilePreviewWidget(GtkFileChooser *
                                                              &preview_width,
                                                              &preview_height);
   if (!preview_format) {
     g_free(image_filename);
     gtk_file_chooser_set_preview_widget_active(file_chooser, FALSE);
     return;
   }
 
-  GdkPixbuf *preview_pixbuf;
+  GdkPixbuf *preview_pixbuf = nullptr;
   // Only scale down images that are too big
   if (preview_width > MAX_PREVIEW_SIZE || preview_height > MAX_PREVIEW_SIZE) {
-    preview_pixbuf = gdk_pixbuf_new_from_file_at_size(image_filename,
-                                                      MAX_PREVIEW_SIZE,
-                                                      MAX_PREVIEW_SIZE,
-                                                      nullptr);
+    if (ceil(preview_width / double(MAX_PREVIEW_SIZE) + 1.0) *
+          ceil(preview_height / double(MAX_PREVIEW_SIZE) + 1.0) < 0x7FFFFF) {
+      preview_pixbuf = gdk_pixbuf_new_from_file_at_size(image_filename,
+                                                        MAX_PREVIEW_SIZE,
+                                                        MAX_PREVIEW_SIZE,
+                                                        nullptr);
+    }
   }
   else {
     preview_pixbuf = gdk_pixbuf_new_from_file(image_filename, nullptr);
   }
 
   g_free(image_filename);
 
   if (!preview_pixbuf) {