https://github.com/gmondada updated https://github.com/llvm/llvm-project/pull/173966
>From 72fe6f3e28d7c67cde32ad7efbcc5fae45e78cbe Mon Sep 17 00:00:00 2001 From: Gabriele Mondada <[email protected]> Date: Mon, 29 Dec 2025 23:28:34 +0100 Subject: [PATCH 1/2] [lldb-server] Fix zip file lookup ignoring last entry in the zip file Command qModuleInfo can be used to request metadata of shared libraries stored in a ZIP archive on the target (typically used for APK on Android). Requesting the last entry in the ZIP file often fails because of a bug in the entry search mechanism. --- lldb/source/Utility/ZipFile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Utility/ZipFile.cpp b/lldb/source/Utility/ZipFile.cpp index b8ed956cbfcb2..e47c690e65b0d 100644 --- a/lldb/source/Utility/ZipFile.cpp +++ b/lldb/source/Utility/ZipFile.cpp @@ -144,7 +144,7 @@ bool FindFile(lldb::DataBufferSP zip_data, const EocdRecord *eocd, // Sanity check the file name values. auto file_name = reinterpret_cast<const char *>(cd + 1); size_t file_name_length = cd->file_name_length; - if (file_name + file_name_length >= reinterpret_cast<const char *>(eocd) || + if (file_name + file_name_length > reinterpret_cast<const char *>(eocd) || file_name_length == 0) return false; >From 6482ca1a78a38273e01214d1f8f413a7a99f77ea Mon Sep 17 00:00:00 2001 From: Gabriele Mondada <[email protected]> Date: Thu, 22 Jan 2026 18:21:29 +0100 Subject: [PATCH 2/2] [lldb] Improve tests for the ZipFileResolver --- lldb/unittests/Host/common/CMakeLists.txt | 1 + .../Host/common/Inputs/zip-test-no-extras.zip | Bin 0 -> 3950 bytes .../Host/common/ZipFileResolverTest.cpp | 50 ++++++++++++------ 3 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 lldb/unittests/Host/common/Inputs/zip-test-no-extras.zip diff --git a/lldb/unittests/Host/common/CMakeLists.txt b/lldb/unittests/Host/common/CMakeLists.txt index 8aa2dfb4e8e1e..3c52f9bf15fbc 100644 --- a/lldb/unittests/Host/common/CMakeLists.txt +++ b/lldb/unittests/Host/common/CMakeLists.txt @@ -12,5 +12,6 @@ add_lldb_unittest(HostCommonTests set(test_inputs zip-test.zip + zip-test-no-extras.zip ) add_unittest_inputs(HostCommonTests "${test_inputs}") diff --git a/lldb/unittests/Host/common/Inputs/zip-test-no-extras.zip b/lldb/unittests/Host/common/Inputs/zip-test-no-extras.zip new file mode 100644 index 0000000000000000000000000000000000000000..f3a75b8817a980e86e453fbe73ecb7a03a3d54ff GIT binary patch literal 3950 zcmbVPPiP!v6o0#$s;#Z2Hl<=~Gl+juFq2KPNjEh}O{-LrLkuDjgw14Tl3lyI6K1C& ziG}9SgNGhkD40W$992A|B3Q6!4<cAZdTFo5gV2LuE=r1;_}<L>?M^3KqJ7Ei?|XlK z@B1_F`(|czIMcF==rN+P!5`nDn6yv}l}nRd8#jqY>rwOH+#mG>GbGCLEB(37*}T=& zh^=w#cc*{2*2+P09oiDh%!SfSXW-TXv*w+9edLXFDpemthQ6YPMs!>~tvl->Y|GP5 z{%xau^az_<_&TocB(7^RAWu3JF$?cOa&kxH0a9zE3r}3IpWLr;idQ0)fN`FTbyf4O zz7PchZ|FFI;H5cCc<ahrR~~Rtc|go>?AO4N`EA#q!G$2AX=qe=<GMIW9E`#Vh&6nR zc{0xbE5es6FB5HoOOcs?=uhT(o-Y~qYgNbhN)E{_@O%1fhKH7czV3nkzTSuCKZq#f ze5#34%Bq?D+0ee5E^A$3-b88sOND<ga*UQG*?Xiw(q!_li1e3Hd`1kk7zT^&qo04j zD*5C>3^%t(cuNWed(J9Mm8w>`wBS;tT7f%P3W)b{LH4nn1~zYI8hLZ*geXo~G!fKy zMkfIMuGTT^@98|(5_asbi!VjPOLHF7s#um{b}gYWFm*8Viqxpo<Zrx4<BWeZ&M>y@ zCHjzYH{&v+!FY{vknt9yNLvJyS{S3$*~6)WyW8vbL)^N+x%j^>5})JiJR7kG#VPg? zzJexphwTpA(HE;>`z+%G+od0f#9Zb};&mzEqQdi;+pMh6;(<%dX%qcMrf^5_pUuq! zf)hkvu4U*m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V?d00001 diff --git a/lldb/unittests/Host/common/ZipFileResolverTest.cpp b/lldb/unittests/Host/common/ZipFileResolverTest.cpp index 12aba31411305..8d54ab4552d6a 100644 --- a/lldb/unittests/Host/common/ZipFileResolverTest.cpp +++ b/lldb/unittests/Host/common/ZipFileResolverTest.cpp @@ -15,12 +15,30 @@ using namespace lldb_private; using namespace llvm; namespace { +struct ZipFileDesc { + std::string zip_name; + std::string lib_path; + size_t lib_offset; + size_t lib_size; +}; + class ZipFileResolverTest : public ::testing::Test { SubsystemRAII<FileSystem> subsystems; }; -std::string TestZipPath() { - FileSpec zip_spec(GetInputFilePath("zip-test.zip")); +std::vector<ZipFileDesc> TestZipFiles() { + return { + // Simple uncompressed zip file, making use of extra fields + {"zip-test.zip", "lib/arm64-v8a/libzip-test.so", 4096, 3600}, + + // Simple uncompressed zip file, where the shared library is the last entry, + // and the enrty has no extra field + {"zip-test-no-extras.zip", "lib/arm64-v8a/libzip-test.so", 140, 3600}, + }; +} + +std::string TestZipPath(const ZipFileDesc& desc) { + FileSpec zip_spec(GetInputFilePath(desc.zip_name)); FileSystem::Instance().Resolve(zip_spec); return zip_spec.GetPath(); } @@ -43,7 +61,7 @@ TEST_F(ZipFileResolverTest, ResolveSharedLibraryPathWithNormalFile) { } TEST_F(ZipFileResolverTest, ResolveSharedLibraryPathWithZipMissing) { - const std::string zip_path = TestZipPath(); + const std::string zip_path = TestZipPath(TestZipFiles().at(0)); const FileSpec file_spec(zip_path + "!/lib/arm64-v8a/libmissing.so"); ZipFileResolver::FileKind file_kind; @@ -55,18 +73,20 @@ TEST_F(ZipFileResolverTest, ResolveSharedLibraryPathWithZipMissing) { } TEST_F(ZipFileResolverTest, ResolveSharedLibraryPathWithZipExisting) { - const std::string zip_path = TestZipPath(); - const FileSpec file_spec(zip_path + "!/lib/arm64-v8a/libzip-test.so"); + for (const auto &zip_desc : TestZipFiles()) { + const std::string zip_path = TestZipPath(zip_desc); + const FileSpec file_spec(zip_path + "!/" + zip_desc.lib_path); - ZipFileResolver::FileKind file_kind; - std::string file_path; - lldb::offset_t file_offset; - lldb::offset_t file_size; - ASSERT_TRUE(ZipFileResolver::ResolveSharedLibraryPath( - file_spec, file_kind, file_path, file_offset, file_size)); + ZipFileResolver::FileKind file_kind; + std::string file_path; + lldb::offset_t file_offset; + lldb::offset_t file_size; + ASSERT_TRUE(ZipFileResolver::ResolveSharedLibraryPath( + file_spec, file_kind, file_path, file_offset, file_size)); - EXPECT_EQ(file_kind, ZipFileResolver::FileKind::eFileKindZip); - EXPECT_EQ(file_path, zip_path); - EXPECT_EQ(file_offset, 4096UL); - EXPECT_EQ(file_size, 3600UL); + EXPECT_EQ(file_kind, ZipFileResolver::FileKind::eFileKindZip); + EXPECT_EQ(file_path, zip_path); + EXPECT_EQ(file_offset, zip_desc.lib_offset); + EXPECT_EQ(file_size, zip_desc.lib_size); + } } _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
