Bug 1184009 - Limit gtk file picker preview source sizes. r=acomminos

This commit is contained in:
Lee Salzman 2015-08-07 12:24:22 -04:00
parent 02a14735f6
commit 90e3e780d3

View File

@ -29,6 +29,8 @@
using namespace mozilla;
#define MAX_PREVIEW_SIZE 180
// bug 1184009
#define MAX_PREVIEW_SOURCE_SIZE 4096
nsIFile *nsFilePicker::mPrevDisplayDirectory = nullptr;
@ -95,7 +97,10 @@ UpdateFilePreviewWidget(GtkFileChooser *file_chooser,
GdkPixbufFormat *preview_format = gdk_pixbuf_get_file_info(image_filename,
&preview_width,
&preview_height);
if (!preview_format) {
if (!preview_format ||
preview_width <= 0 || preview_height <= 0 ||
preview_width > MAX_PREVIEW_SOURCE_SIZE ||
preview_height > MAX_PREVIEW_SOURCE_SIZE) {
g_free(image_filename);
gtk_file_chooser_set_preview_widget_active(file_chooser, FALSE);
return;
@ -104,13 +109,10 @@ UpdateFilePreviewWidget(GtkFileChooser *file_chooser,
GdkPixbuf *preview_pixbuf = nullptr;
// Only scale down images that are too big
if (preview_width > MAX_PREVIEW_SIZE || preview_height > MAX_PREVIEW_SIZE) {
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);
}
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);