fix: in GTK open dialog, do not preview huge files (#31799)
This commit is contained in:
parent
a6a5ca1db3
commit
c8ba3b4556
1 changed files with 16 additions and 4 deletions
|
@ -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) {
|
void FileChooserDialog::OnUpdatePreview(GtkFileChooser* chooser) {
|
||||||
CHECK(!*supports_gtk_file_chooser_native);
|
CHECK(!*supports_gtk_file_chooser_native);
|
||||||
gchar* filename = gtk_file_chooser_get_preview_filename(chooser);
|
gchar* filename = gtk_file_chooser_get_preview_filename(chooser);
|
||||||
|
@ -377,10 +391,8 @@ void FileChooserDialog::OnUpdatePreview(GtkFileChooser* chooser) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't attempt to open anything which isn't a regular file. If a named
|
struct stat sb;
|
||||||
// pipe, this may hang. See https://crbug.com/534754.
|
if (stat(filename, &sb) != 0 || !CanPreview(sb)) {
|
||||||
struct stat stat_buf;
|
|
||||||
if (stat(filename, &stat_buf) != 0 || !S_ISREG(stat_buf.st_mode)) {
|
|
||||||
g_free(filename);
|
g_free(filename);
|
||||||
gtk_file_chooser_set_preview_widget_active(chooser, FALSE);
|
gtk_file_chooser_set_preview_widget_active(chooser, FALSE);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue