================
@@ -147,6 +147,32 @@ def test_target_create_unsupported_platform(self):
             patterns=["error: no matching platforms found for this file"],
         )
 
+    @no_debug_info_test
+    def test_target_create_fat_macho_huge_nfat_arch(self):
+        """A fat Mach-O header whose nfat_arch is larger than the data must not
+        send the arch-indexing loop spinning."""
+        yaml = os.path.join(self.getSourceDir(), "fat_nfat_arch_huge.yaml")
+        exe = self.getBuildArtifact("fat_nfat_arch_huge")
+        self.yaml2obj(yaml, exe)
+        # Before the fix this loops ~0xFFFFFFFF times and test timeout.  The
+        # test "passing" here just means target create completes promptly.
+        self.expect("target create {}".format(exe))
+
+    @no_debug_info_test
+    def test_target_create_fat_macho_self_referential_slice(self):
+        """A fat Mach-O slice at offset 0 is self-referential.  Parsing it must
+        not recurse until the stack overflows."""
+        yaml = os.path.join(self.getSourceDir(), "fat_slice_offset_zero.yaml")
+        exe = self.getBuildArtifact("fat_slice_offset_zero")
+        self.yaml2obj(yaml, exe)
+        # Before the fix this recurses on identical arguments and crashes.  The
+        # non-advancing slice is now skipped, leaving nothing loadable.
+        self.expect(
+            "target create {}".format(exe),
+            error=True,
+            patterns=["is not a valid executable"],
+        )
----------------
qiyao wrote:

The new commit adds a new dir `lldb/unittests/ObjectContainer/`, and has one 
unit test `ObjectContainerUniversalMachOTest.cpp`.  Note that without code fix, 
`TEST_F(ObjectContainerUniversalMachOTest, HugeNfatArch)` runs slow to some 
extent (about 6 seconds), it is expected, but it isn't slow enough to get a 
timeout error.

`TEST_F(ObjectContainerUniversalMachOTest, SliceOffsetZero)` can reproduce a 
stack overflow on the code without fix.

https://github.com/llvm/llvm-project/pull/204471
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to