diff options
author | Winson <chiuwinson@google.com> | 2019-01-23 12:39:40 -0800 |
---|---|---|
committer | Winson <chiuwinson@google.com> | 2019-01-24 16:10:16 -0800 |
commit | f54c9a1d72aa3f307e6d78b7f9221354d72fc6e1 (patch) | |
tree | 664f1f24f58a89a407724aebdf85135eae396190 /tools/aapt2/cmd/Convert_test.cpp | |
parent | 3b943e777e57c6f3c7351c23daea2f12ac8ea928 (diff) |
De-duplicate entries written with AAPT2 convert
There was no check for whether we had already written a specific file path to the APK when using the convert command.
If the resources table points 2 resource IDs at the same file on disk, the convert command would write the file twice, creating two entries.
This holds a set of file paths already written and ignores duplicates.
Bug: 123271593
Test: Ran convert on linked bug's weird.apk
Test: aapt2_tests case for duplicate entries
Change-Id: Ia22515bf8e8297624aaadbf6a9e47159026c63e5
Diffstat (limited to 'tools/aapt2/cmd/Convert_test.cpp')
-rw-r--r-- | tools/aapt2/cmd/Convert_test.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/aapt2/cmd/Convert_test.cpp b/tools/aapt2/cmd/Convert_test.cpp index 2e4315086105..77cdc41d1a65 100644 --- a/tools/aapt2/cmd/Convert_test.cpp +++ b/tools/aapt2/cmd/Convert_test.cpp @@ -18,6 +18,7 @@ #include "LoadedApk.h" #include "test/Test.h" +#include "ziparchive/zip_archive.h" using testing::Eq; using testing::Ne; @@ -95,4 +96,45 @@ TEST_F(ConvertTest, KeepRawXmlStrings) { EXPECT_THAT(util::GetString(tree.getStrings(), static_cast<size_t>(raw_index)), Eq("007")); } +TEST_F(ConvertTest, DuplicateEntriesWrittenOnce) { + StdErrDiagnostics diag; + const std::string apk_path = + file::BuildPath({android::base::GetExecutableDirectory(), + "integration-tests", "ConvertTest", "duplicate_entries.apk"}); + + const std::string out_convert_apk = GetTestPath("out_convert.apk"); + std::vector<android::StringPiece> convert_args = { + "-o", out_convert_apk, + "--output-format", "proto", + apk_path + }; + ASSERT_THAT(ConvertCommand().Execute(convert_args, &std::cerr), Eq(0)); + + ZipArchiveHandle handle; + ASSERT_THAT(OpenArchive(out_convert_apk.c_str(), &handle), Eq(0)); + + void* cookie = nullptr; + + ZipString prefix("res/theme/10"); + int32_t result = StartIteration(handle, &cookie, &prefix, nullptr); + + // If this is -5, that means we've found a duplicate entry and this test has failed + EXPECT_THAT(result, Eq(0)); + + // But if read succeeds, verify only one res/theme/10 entry + int count = 0; + + // Can't pass nullptrs into Next() + ZipString zip_name; + ZipEntry zip_data; + + while ((result = Next(cookie, &zip_data, &zip_name)) == 0) { + count++; + } + + EndIteration(cookie); + + EXPECT_THAT(count, Eq(1)); +} + } // namespace aapt
\ No newline at end of file |