4
4
5
5
#include " content/browser/file_system_access/file_system_chooser.h"
6
6
7
- #include " base/bind.h"
8
7
#include " base/files/file_path.h"
9
- #include " base/files/file_util.h"
10
8
#include " base/i18n/file_util_icu.h"
11
9
#include " base/i18n/rtl.h"
12
10
#include " base/metrics/histogram_functions.h"
13
11
#include " base/strings/string_util.h"
14
12
#include " base/strings/utf_string_conversions.h"
15
13
#include " build/build_config.h"
16
- #include " content/browser/file_system_access/file_system_access_directory_handle_impl.h"
17
14
#include " content/browser/file_system_access/file_system_access_error.h"
18
15
#include " content/public/browser/browser_thread.h"
19
- #include " content/public/browser/child_process_security_policy.h"
20
16
#include " content/public/browser/content_browser_client.h"
21
17
#include " content/public/browser/web_contents.h"
22
18
#include " content/public/common/content_client.h"
23
- #include " net/base/filename_util.h"
24
19
#include " net/base/mime_util.h"
25
20
#include " ui/gfx/text_elider.h"
26
21
#include " ui/shell_dialogs/select_file_policy.h"
@@ -36,6 +31,10 @@ namespace {
36
31
// size and underlying platform all influence how many characters will actually
37
32
// be visible. As such this can be adjusted as needed.
38
33
constexpr int kMaxDescriptionLength = 64 ;
34
+ // The maximum number of unicode code points the extension of a file is
35
+ // allowed to be. Any longer extensions will be stripped. This value should be
36
+ // kept in sync with the extension length checks in the renderer.
37
+ constexpr int kMaxExtensionLength = 16 ;
39
38
40
39
std::string TypeToString (ui::SelectFileDialog::Type type) {
41
40
switch (type) {
@@ -214,6 +213,12 @@ base::FilePath FileSystemChooser::Options::ResolveSuggestedNameExtension(
214
213
215
214
auto suggested_extension = suggested_name.Extension ();
216
215
216
+ if (suggested_extension.size () > kMaxExtensionLength ) {
217
+ // Sanitize extensions longer than 16 characters.
218
+ file_types.include_all_files = true ;
219
+ return suggested_name.RemoveExtension ();
220
+ }
221
+
217
222
if (file_types.extensions .empty () || suggested_extension.empty ()) {
218
223
file_types.include_all_files = true ;
219
224
return suggested_name;
0 commit comments