Skip to content

Commit

Permalink
add: check string max length
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-wu committed Jul 31, 2021
1 parent 630499b commit ff4dd8f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Binary file modified Demo/SwiftDump
Binary file not shown.
8 changes: 8 additions & 0 deletions SwiftDump/SwiftDump/SDParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -627,11 +627,19 @@ func dumpFieldDescriptor(loader: SDFileLoader, fieldDescriptorPtr: SDPointer, to
let typeNamePtr = loader.readMove(fieldAddr.add(4)).fix();
let typeName = loader.readStr(typeNamePtr);

if let type = typeName, (type.count <= 0 || type.count > 100) {
continue
}

let fieldNamePtr = loader.readMove(fieldAddr.add(8)).fix();
let fieldName = loader.readStr(fieldNamePtr);

if let field = fieldName, (field.count <= 0 || field.count > 100) {
continue
}

if let type = typeName, let field = fieldName {

let realType = getTypeFromMangledName(type);
let fieldObj = SDNominalObjField();
fieldObj.name = field; // name: field, type: realType
Expand Down
4 changes: 4 additions & 0 deletions SwiftDump/SwiftDump/Util/Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ extension Data {
}
}

if (result.count > 10000) {
return nil
}

let tmp = result.reduce("0x") { (result, val:UInt8) -> String in
return result + String(format: "%02x", val);
}
Expand Down
8 changes: 7 additions & 1 deletion SwiftDump/SwiftDump/Util/RuntimeBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ func getTypeFromMangledName(_ str: String) -> String {
guard let ptr = str.toPointer() else {
return str;
}
guard let typeRet: Any.Type = _getTypeByMangledNameInContext(ptr, str.count, genericContext: nil, genericArguments: nil) else {

var useCnt:Int = str.count
if (str.hasSuffix("_pG")) {
useCnt = useCnt - 3
}

guard let typeRet: Any.Type = _getTypeByMangledNameInContext(ptr, useCnt, genericContext: nil, genericArguments: nil) else {
return str;
}

Expand Down

0 comments on commit ff4dd8f

Please sign in to comment.