Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1184009 - Limit gtk file picker preview source sizes. r=acomminos
Browse files Browse the repository at this point in the history
  • Loading branch information
lsalzman committed Aug 7, 2015
1 parent f5a040b commit 78cfa8f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions widget/gtk/nsFilePicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
using namespace mozilla;

#define MAX_PREVIEW_SIZE 180
// bug 1184009
#define MAX_PREVIEW_SOURCE_SIZE 4096

nsIFile *nsFilePicker::mPrevDisplayDirectory = nullptr;

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 78cfa8f

Please sign in to comment.