From b49783a8dee4e51beacd22c3049d2f10a14cbe00 Mon Sep 17 00:00:00 2001 From: mkarolin Date: Fri, 22 Apr 2022 14:48:23 -0400 Subject: [PATCH] Fixes https everywhere not working with existing database. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We use third_party/zlib to unzip HTTPS Everywhere database from a zip file. Chromium recently changed unzip behavior to error out if the target file already exists (previously it happily overrode existing files). This caused our code that unzips the file to error out and not load the db. Changed our code to delete existing unzipped directory before unzipping. Chromium change: https://chromium.googlesource.com/chromium/src/+/7ba6004ba3727e9f5339841cfe0f54e7e51dfbf2 commit 7ba6004ba3727e9f5339841cfe0f54e7e51dfbf2 Author: François Degros Date: Thu Mar 17 05:46:45 2022 +0000 [zip] Unzip() does not overwrite files anymore Changed the way FilePathWriterDelegate creates a new file, by using FLAG_CREATE instead of FLAG_CREATE_ALWAYS. This prevents FilePathWriterDelegate and zip::Unzip() from overwriting any existing file. This allows the detection of duplicated or conflicting file names when extracting a ZIP archive. See ZipTest.UnzipRepeatedFileName. This fixes a confusing corner case on case-insensitive file systems, which could result in file contents not matching file names as stored in the ZIP archive. See ZipTest.UnzipDifferentCases. BUG=chromium:953256 --- .../brave_shields/browser/https_everywhere_service.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/components/brave_shields/browser/https_everywhere_service.cc b/components/brave_shields/browser/https_everywhere_service.cc index ccbf3bc541fd..65ca0121ba40 100644 --- a/components/brave_shields/browser/https_everywhere_service.cc +++ b/components/brave_shields/browser/https_everywhere_service.cc @@ -12,6 +12,7 @@ #include "base/base_paths.h" #include "base/bind.h" +#include "base/files/file_util.h" #include "base/json/json_reader.h" #include "base/logging.h" #include "base/memory/ptr_util.h" @@ -90,6 +91,15 @@ void HTTPSEverywhereService::Engine::Init(const base::FilePath& base_dir) { base_dir.AppendASCII(DAT_FILE_VERSION).AppendASCII(DAT_FILE); base::FilePath unzipped_level_db_path = zip_db_file_path.RemoveExtension(); base::FilePath destination = zip_db_file_path.DirName(); + // Unzip doesn't allow overwriting existing files, so delete previously + // unzipped db. Attempting to delete a non-existent path returns success. + bool deleted = base::DeletePathRecursively(unzipped_level_db_path); + if (!deleted) { + LOG(ERROR) << "Failed to delete unzipped database directory " + << unzipped_level_db_path.value().c_str(); + return; + } + if (!zip::Unzip(zip_db_file_path, destination)) { LOG(ERROR) << "Failed to unzip database file " << zip_db_file_path.value().c_str();