llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-lldb Author: nerix (Nerixyz) <details> <summary>Changes</summary> The formatter extraction would look at too much data for one type. This PR limits the size of the `DataExtractor` to the one specified in the record size before - previously, the whole section was looked at. Similarly, `ForEachFormatterInModule` skipped zero-bytes but didn't stop when reaching the end of the extractor. I hit both cases in an even smaller test than the one currently in the repo, but I tried this on Windows[^1]. In my executable, the formatter section started with my specified formatter and was padded to 512 bytes with zeroes. I'd guess this should've come up in the existing test case, so macOS might do something different here[?]. <details><summary>Test File</summary> ```c struct Point { int x; int y; }; __attribute__((used, section(".lldbformatters"))) const char my_string[] = { 0x01, // version 0x12, // record size 0x05, // type size 'P', 'o', 'i', 'n', 't', 0x00, // flags 0x00, // signature 0x09, // byte-code length 0x01, // drop 0x22, // push str 0x05, // str len 'A', 'A', 'A', 'A', 'A', 0x13, // return }; int main() { Point a{3, 4}; return a.x + a.y; // break here } ``` </details> [^1]: I had to change the section name matching to use an 8 byte name in the [PE/COFF](https://github.com/llvm/llvm-project/blob/acdba28e148ac1e94d6c041f9911230e1e90e9cd/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp#L1003) reader, since executables on Windows [can't have section names longer than 8 bytes](https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#section-table-section-headers) (actually they can, and in MinGW they do, but I couldn't get `clang-cl` to generate such a binary). --- Full diff: https://github.com/llvm/llvm-project/pull/140139.diff 1 Files Affected: - (modified) lldb/source/DataFormatters/FormatterSection.cpp (+6-2) ``````````diff diff --git a/lldb/source/DataFormatters/FormatterSection.cpp b/lldb/source/DataFormatters/FormatterSection.cpp index 1de633f4998e0..72979ac1923e8 100644 --- a/lldb/source/DataFormatters/FormatterSection.cpp +++ b/lldb/source/DataFormatters/FormatterSection.cpp @@ -57,11 +57,15 @@ static void ForEachFormatterInModule( cursor.seek(cursor.tell() - 1); break; } + if (!cursor || cursor.tell() >= section_size) + break; + uint64_t version = section.getULEB128(cursor); uint64_t record_size = section.getULEB128(cursor); if (version == 1) { - llvm::DataExtractor record(section.getData().drop_front(cursor.tell()), - le, addr_size); + llvm::DataExtractor record( + section.getData().drop_front(cursor.tell()).take_front(record_size), + le, addr_size); llvm::DataExtractor::Cursor cursor(0); uint64_t type_size = record.getULEB128(cursor); llvm::StringRef type_name = record.getBytes(cursor, type_size); `````````` </details> https://github.com/llvm/llvm-project/pull/140139 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits