Commit 7c2651c6 authored by Daniel Rubery's avatar Daniel Rubery Committed by Commit Bot

Report the number of files within RAR file to SafeBrowsing

The backend team has asked that we send the total count of files and
directories within archives. This CL adds this information to the
download ping for RAR archives.

Bug: 926586
Change-Id: Id24838c5984a72740ff3776dd26ef49965113d7b
Reviewed-on: https://chromium-review.googlesource.com/c/1487193Reviewed-by: default avatarVarun Khaneja <vakh@chromium.org>
Commit-Queue: Varun Khaneja <vakh@chromium.org>
Auto-Submit: Daniel Rubery <drubery@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635629}
parent 229c4286
......@@ -268,6 +268,9 @@ void FileAnalyzer::OnRarAnalysisFinished(
results_.type = ClientDownloadRequest::RAR_COMPRESSED_EXECUTABLE;
}
results_.file_count = archive_results.file_count;
results_.directory_count = archive_results.directory_count;
std::move(callback_).Run(std::move(results_));
}
......
......@@ -829,4 +829,52 @@ TEST_F(FileAnalyzerTest, ZipFilesGetDirectoryCount) {
EXPECT_EQ(1, result_.directory_count);
}
TEST_F(FileAnalyzerTest, RarFilesGetFileCount) {
scoped_refptr<MockBinaryFeatureExtractor> extractor =
new testing::StrictMock<MockBinaryFeatureExtractor>();
FileAnalyzer analyzer(extractor);
base::RunLoop run_loop;
base::FilePath target_path(FILE_PATH_LITERAL("has_exe.rar"));
base::FilePath rar_path;
EXPECT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &rar_path));
rar_path = rar_path.AppendASCII("safe_browsing")
.AppendASCII("rar")
.AppendASCII("has_exe.rar");
analyzer.Start(
target_path, rar_path,
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
run_loop.QuitClosure()));
run_loop.Run();
ASSERT_TRUE(has_result_);
EXPECT_EQ(1, result_.file_count);
EXPECT_EQ(0, result_.directory_count);
}
TEST_F(FileAnalyzerTest, RarFilesGetDirectoryCount) {
scoped_refptr<MockBinaryFeatureExtractor> extractor =
new testing::StrictMock<MockBinaryFeatureExtractor>();
FileAnalyzer analyzer(extractor);
base::RunLoop run_loop;
base::FilePath target_path(FILE_PATH_LITERAL("has_folder.rar"));
base::FilePath rar_path;
EXPECT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &rar_path));
rar_path = rar_path.AppendASCII("safe_browsing")
.AppendASCII("rar")
.AppendASCII("has_folder.rar");
analyzer.Start(
target_path, rar_path,
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
run_loop.QuitClosure()));
run_loop.Run();
ASSERT_TRUE(has_result_);
EXPECT_EQ(0, result_.file_count);
EXPECT_EQ(1, result_.directory_count);
}
} // namespace safe_browsing
......@@ -24,6 +24,8 @@ void AnalyzeRarFile(base::File rar_file,
base::File temp_file,
ArchiveAnalyzerResults* results) {
results->success = false;
results->file_count = 0;
results->directory_count = 0;
auto archive = std::make_unique<third_party_unrar::Archive>();
archive->SetFileHandle(rar_file.GetPlatformFile());
......@@ -81,6 +83,11 @@ void AnalyzeRarFile(base::File rar_file,
UpdateArchiveAnalyzerResultsWithFile(
file_path, &temp_file, archive->FileHead.Encrypted, results);
if (archive->FileHead.Dir)
results->directory_count++;
else
results->file_count++;
}
}
} else {
......@@ -96,7 +103,6 @@ void AnalyzeRarFile(base::File rar_file,
std::string filename(wide_filename.begin(), wide_filename.end());
base::FilePath file_path(filename);
#endif // OS_WIN
bool is_executable =
FileTypePolicies::GetInstance()->IsCheckedBinaryFile(file_path);
bool is_archive =
......@@ -110,6 +116,11 @@ void AnalyzeRarFile(base::File rar_file,
bool is_utf8_valid_basename =
base::StreamingUtf8Validator::Validate(basename_utf8);
if (archive->FileHead.Dir)
results->directory_count++;
else
results->file_count++;
if (is_archive) {
results->has_archive = true;
archived_archive_filenames.insert(basename);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment