8000 fix: in GTK open dialog, do not preview huge files by trop[bot] · Pull Request #31820 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: in GTK open dialog, do not preview huge files #31820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
20 changes: 16 additions & 4 deletions shell/browser/ui/file_dialog_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,20 @@ void FileChooserDialog::AddFilters(const Filters& filters) {
}
}

bool CanPreview(const struct stat& st) {
// Only preview regular files; pipes may hang.
// See https://crbug.com/534754.
if (!S_ISREG(st.st_mode)) {
return false;
}

// Don't preview huge files; they may crash.
// https://github.com/electron/electron/issues/31630
// Setting an arbitrary filesize max t at 100 MB here.
constexpr off_t ArbitraryMax = 100000000ULL;
return st.st_size < ArbitraryMax;
}

void FileChooserDialog::OnUpdatePreview(GtkFileChooser* chooser) {
CHECK(!*supports_gtk_file_chooser_native);
gchar* filename = gtk_file_chooser_get_preview_filename(chooser);
Expand All @@ -377,10 +391,8 @@ void FileChooserDialog::OnUpdatePreview(GtkFileChooser* chooser) {
return;
}

// Don't attempt to open anything which isn't a regular file. If a named
// pipe, this may hang. See https://crbug.com/534754.
struct stat stat_buf;
if (stat(filename, &stat_buf) != 0 || !S_ISREG(stat_buf.st_mode)) {
struct stat sb;
if (stat(filename, &sb) != 0 || !CanPreview(sb)) {
g_free(filename);
gtk_file_chooser_set_preview_widget_active(chooser, FALSE);
return;
Expand Down
0