llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) <details> <summary>Changes</summary> 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 --- Full diff: https://github.com/llvm/llvm-project/pull/175181.diff 2 Files Affected: - (modified) lldb/source/Symbol/ObjectFile.cpp (+8-5) - (added) lldb/test/Shell/ObjectFile/invalid.test (+4) ``````````diff 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 `````````` </details> https://github.com/llvm/llvm-project/pull/175181 _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
