diff options
| author | Mason Reed <mason@vector35.com> | 2026-05-29 18:16:58 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2026-06-02 12:29:01 -0700 |
| commit | 5fe1980a95f956c1f58974de27fbbfbfac1258af (patch) | |
| tree | 807b3581a5f219be80b9ec486130a068db26823f | |
| parent | 5953d087a9a104e7abb63c5739091214edf2faca (diff) | |
[Objective-C] Improve bounds checking on UTF8 cf strings
Cont. 02e67da266d21e106d0b9900a2a98dbf8d045ad2
We don't really need to do the same check for the non-utf8 variant since it uses the ReadCString function.
| -rw-r--r-- | objectivec/objc.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/objectivec/objc.cpp b/objectivec/objc.cpp index 72f07c9c..d3ab8525 100644 --- a/objectivec/objc.cpp +++ b/objectivec/objc.cpp @@ -1694,16 +1694,17 @@ void ObjCProcessor::ProcessCFStrings() reader->Seek(i + ptrSize); uint64_t flags = reader->ReadPointer(); const auto strLoc = ReadPointerAccountingForRelocations(reader.get()); - const auto size = reader->ReadPointer(); - if (!m_data->IsValidOffset(strLoc + size)) - { - m_logger->LogWarn("CFString at 0x%llx has invalid size 0x%llx, skipping...", i, size); - continue; - } + const auto strLen = reader->ReadPointer(); std::string str; if (flags & 0b10000) // UTF16 { - auto data = m_data->ReadBuffer(strLoc, size * 2); + const auto strSize = strLen * 2; + if (!m_data->IsValidOffset(strLoc + strSize)) + { + m_logger->LogWarn("CFString at 0x%llx has invalid length 0x%llx, skipping...", i, strLen); + continue; + } + auto data = m_data->ReadBuffer(strLoc, strSize); str = ""; for (uint64_t bufferOff = 0; bufferOff + 1 < data.GetLength(); bufferOff += 2) @@ -1729,14 +1730,14 @@ void ObjCProcessor::ProcessCFStrings() } } DefineObjCSymbol( - DataSymbol, Type::ArrayType(Type::WideCharType(2), size + 1), "ustr_" + str, strLoc, true); + DataSymbol, Type::ArrayType(Type::WideCharType(2), strLen + 1), "ustr_" + str, strLoc, true); DefineObjCSymbol( DataSymbol, Type::NamedType(m_data, m_typeNames.cfStringUTF16), "cfstr_" + str, i, true); } else // UTF8 / ASCII { reader->Seek(strLoc); - std::string rawStr = reader->ReadCString(size + 1); + std::string rawStr = reader->ReadCString(strLen + 1); str = ""; for (signed char c : rawStr) { |
