Ghidra is a software reverse engineering (SRE) framework
Fixes crash in pdb.exe on rust pdb's
Toshi Piazza6741ad266cd1
diff --git a/Ghidra/Features/PDB/src/pdb/cpp/iterate.cpp b/Ghidra/Features/PDB/src/pdb/cpp/iterate.cppindex ff2478a94c..f4ee2c7605 100644--- a/Ghidra/Features/PDB/src/pdb/cpp/iterate.cpp+++ b/Ghidra/Features/PDB/src/pdb/cpp/iterate.cpp@@ -324,7 +324,7 @@ void dumpFunctionLines( IDiaSymbol& symbol, IDiaSession& session )pLine->get_lineNumberEnd( &end );printf("%S<line_number source_file=\"%ws\" start=\"%d\" end=\"%d\" addr=\"0x%x\" /> \n",- indent(12).c_str(), sourceFileName.GetBSTR(), start, end, addr);+ indent(12).c_str(), escapeXmlEntities(sourceFileName.GetBSTR()).data(), start, end, addr);}}@@ -401,7 +401,7 @@ void iterateSourceFiles(IDiaEnumSourceFiles * pSourceFiles) {bstr_t name;DWORD id = 0;if( (pSourceFile->get_fileName( name.GetAddress() ) == S_OK) && (pSourceFile->get_uniqueId( &id ) == S_OK) ) {- printf("%S<source_file name=\"%ws\" id=\"0x%x\" /> \n", indent(12).c_str(), name.GetBSTR(), id);+ printf("%S<source_file name=\"%ws\" id=\"0x%x\" /> \n", indent(12).c_str(), escapeXmlEntities(name.GetBSTR()).data(), id);}pSourceFile = NULL;}diff --git a/Ghidra/Features/PDB/src/pdb/cpp/print.cpp b/Ghidra/Features/PDB/src/pdb/cpp/print.cppindex 7e15430070..17257f0aa9 100644--- a/Ghidra/Features/PDB/src/pdb/cpp/print.cpp+++ b/Ghidra/Features/PDB/src/pdb/cpp/print.cpp@@ -152,12 +152,16 @@ std::wstring printType( IDiaSymbol * pType, const std::wstring& suffix ) {}ULONGLONG lenArray = getLength( *pType );ULONGLONG lenElem = getLength( *pBaseType );- if (lenElem == 0) {//prevent divide by zero...- lenElem = lenArray;+ ULONGLONG sz;+ if (lenElem == 0) {+ sz = 0;//prevent divide by zero...+ }+ else {+ sz = lenArray / lenElem;}const size_t strLen = suffix.length() + 64 + 3; // length of suffix + wag_for_numeric_value + "[]\0"std::vector<wchar_t> str(strLen);- swprintf_s(str.data(), strLen, L"%s[%I64d]", suffix.c_str(), lenArray / lenElem);+ swprintf_s(str.data(), strLen, L"%s[%I64d]", suffix.c_str(), sz);return printType(pBaseType, str.data());}