Author: Jonas Devlieghere
Date: 2026-01-09T11:29:31-06:00
New Revision: 17e226f71e1c4704ba028adbd799c3932b8c5862

URL: 
https://github.com/llvm/llvm-project/commit/17e226f71e1c4704ba028adbd799c3932b8c5862
DIFF: 
https://github.com/llvm/llvm-project/commit/17e226f71e1c4704ba028adbd799c3932b8c5862.diff

LOG: [lldb] Fix crash when passing a folder in as the executable (#175181)

This is another instance where we weren't checking that the result of
FileSystem::CreateDataBuffer and unconditionally accessing it, similar
to the bug in SourceManager last week. In this particular case,
ObjectFile was assuming that we can read the contents non-zero, which
isn't true for directory nodes.

Jim figured this one out yesterday. I'm just putting up the patch and
adding a test.

rdar://167796036

Added: 
    lldb/test/Shell/ObjectFile/invalid.test

Modified: 
    lldb/source/Symbol/ObjectFile.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Symbol/ObjectFile.cpp 
b/lldb/source/Symbol/ObjectFile.cpp
index 28d811db22a1c..1dfd84c4b61e3 100644
--- a/lldb/source/Symbol/ObjectFile.cpp
+++ b/lldb/source/Symbol/ObjectFile.cpp
@@ -84,11 +84,14 @@ ObjectFileSP ObjectFile::FindPlugin(const lldb::ModuleSP 
&module_sp,
     // container plug-ins can use these bytes to see if they can parse this
     // file.
     if (file_size > 0) {
-      DataBufferSP buffer_sp = FileSystem::Instance().CreateDataBuffer(
-          file->GetPath(), g_initial_bytes_to_read, file_offset);
-      extractor_sp = std::make_shared<DataExtractor>();
-      extractor_sp->SetData(buffer_sp, data_offset, buffer_sp->GetByteSize());
-      data_offset = 0;
+      // Check that we made a data buffer. For instance, a directory node is
+      // not 0 size, but we can't make a data buffer for it.
+      if (DataBufferSP buffer_sp = FileSystem::Instance().CreateDataBuffer(
+              file->GetPath(), g_initial_bytes_to_read, file_offset)) {
+        extractor_sp = std::make_shared<DataExtractor>();
+        extractor_sp->SetData(buffer_sp, data_offset, 
buffer_sp->GetByteSize());
+        data_offset = 0;
+      }
     }
   }
 

diff  --git a/lldb/test/Shell/ObjectFile/invalid.test 
b/lldb/test/Shell/ObjectFile/invalid.test
new file mode 100644
index 0000000000000..5e30f6aee753d
--- /dev/null
+++ b/lldb/test/Shell/ObjectFile/invalid.test
@@ -0,0 +1,4 @@
+RUN: mkdir -p %t.dir
+RUN: %lldb %t.dir 2>&1| FileCheck %s
+
+CHECK: error: '{{.*}}.dir' is not a valid executable


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

Reply via email to