diff --git a/chrome/browser/ui/webui/updater/updater_page_handler.cc b/chrome/browser/ui/webui/updater/updater_page_handler.cc index a99a9f384125d..fd78c9ef90d2c 100644 --- a/chrome/browser/ui/webui/updater/updater_page_handler.cc +++ b/chrome/browser/ui/webui/updater/updater_page_handler.cc @@ -14,6 +14,7 @@ #include "base/barrier_closure.h" #include "base/containers/flat_map.h" +#include "base/files/file.h" #include "base/files/file_enumerator.h" #include "base/files/file_path.h" #include "base/files/file_util.h" @@ -226,7 +227,14 @@ void UnzipUpdaterHistoryFilesImpl( } base::FilePath archive_path = temp_dir.GetPath().AppendASCII("input.zip"); - if (!base::WriteFile(archive_path, zip_data)) { + // FLAG_CREATE -> O_CREAT|O_EXCL on POSIX: refuses to open through a + // pre-existing dentry (including a symlink planted by another process that + // shares the temp directory), so the user-supplied bytes can only land in a + // freshly-created regular file inside the just-mkdtemp'd directory. + base::File archive(archive_path, + base::File::FLAG_CREATE | base::File::FLAG_WRITE); + if (!archive.IsValid() || + !archive.WriteAtCurrentPosAndCheck(base::span(zip_data))) { std::move(callback).Run( base::unexpected(updater_ui::mojom::UnzipUpdaterHistoryFilesError::New( "Failed to write user-supplied zip data to storage")));