mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Fix crash
This commit is contained in:
parent
88b1dab7ff
commit
fb0824ed8b
@ -716,76 +716,82 @@ public final class PostboxDecoder {
|
|||||||
self.buffer = buffer
|
self.buffer = buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
private class func skipValue(_ bytes: UnsafePointer<Int8>, offset: inout Int, length: Int, valueType: ValueType) {
|
private class func skipValue(_ bytes: UnsafePointer<Int8>, offset: inout Int, length: Int, valueType: ValueType) -> Bool {
|
||||||
switch valueType {
|
switch valueType {
|
||||||
case .Int32:
|
case .Int32:
|
||||||
offset += 4
|
offset += 4
|
||||||
case .Int64:
|
case .Int64:
|
||||||
offset += 8
|
offset += 8
|
||||||
case .Bool:
|
case .Bool:
|
||||||
offset += 1
|
offset += 1
|
||||||
case .Double:
|
case .Double:
|
||||||
offset += 8
|
offset += 8
|
||||||
case .String:
|
case .String:
|
||||||
var length: Int32 = 0
|
var length: Int32 = 0
|
||||||
memcpy(&length, bytes + offset, 4)
|
memcpy(&length, bytes + offset, 4)
|
||||||
offset += 4 + Int(length)
|
offset += 4 + Int(length)
|
||||||
case .Object:
|
case .Object:
|
||||||
var length: Int32 = 0
|
var length: Int32 = 0
|
||||||
memcpy(&length, bytes + (offset + 4), 4)
|
memcpy(&length, bytes + (offset + 4), 4)
|
||||||
offset += 8 + Int(length)
|
offset += 8 + Int(length)
|
||||||
case .Int32Array:
|
case .Int32Array:
|
||||||
var length: Int32 = 0
|
var length: Int32 = 0
|
||||||
memcpy(&length, bytes + offset, 4)
|
memcpy(&length, bytes + offset, 4)
|
||||||
offset += 4 + Int(length) * 4
|
offset += 4 + Int(length) * 4
|
||||||
case .Int64Array:
|
case .Int64Array:
|
||||||
var length: Int32 = 0
|
var length: Int32 = 0
|
||||||
memcpy(&length, bytes + offset, 4)
|
memcpy(&length, bytes + offset, 4)
|
||||||
offset += 4 + Int(length) * 8
|
offset += 4 + Int(length) * 8
|
||||||
case .ObjectArray:
|
case .ObjectArray:
|
||||||
var length: Int32 = 0
|
var subLength: Int32 = 0
|
||||||
memcpy(&length, bytes + offset, 4)
|
memcpy(&subLength, bytes + offset, 4)
|
||||||
offset += 4
|
offset += 4
|
||||||
var i: Int32 = 0
|
var i: Int32 = 0
|
||||||
while i < length {
|
while i < subLength {
|
||||||
var objectLength: Int32 = 0
|
var objectLength: Int32 = 0
|
||||||
memcpy(&objectLength, bytes + (offset + 4), 4)
|
memcpy(&objectLength, bytes + (offset + 4), 4)
|
||||||
offset += 8 + Int(objectLength)
|
offset += 8 + Int(objectLength)
|
||||||
i += 1
|
if offset < 0 || offset > length {
|
||||||
}
|
offset = 0
|
||||||
case .ObjectDictionary:
|
return false
|
||||||
var length: Int32 = 0
|
|
||||||
memcpy(&length, bytes + offset, 4)
|
|
||||||
offset += 4
|
|
||||||
var i: Int32 = 0
|
|
||||||
while i < length {
|
|
||||||
var keyLength: Int32 = 0
|
|
||||||
memcpy(&keyLength, bytes + (offset + 4), 4)
|
|
||||||
offset += 8 + Int(keyLength)
|
|
||||||
|
|
||||||
var valueLength: Int32 = 0
|
|
||||||
memcpy(&valueLength, bytes + (offset + 4), 4)
|
|
||||||
offset += 8 + Int(valueLength)
|
|
||||||
i += 1
|
|
||||||
}
|
|
||||||
case .Bytes:
|
|
||||||
var length: Int32 = 0
|
|
||||||
memcpy(&length, bytes + offset, 4)
|
|
||||||
offset += 4 + Int(length)
|
|
||||||
case .Nil:
|
|
||||||
break
|
|
||||||
case .StringArray, .BytesArray:
|
|
||||||
var length: Int32 = 0
|
|
||||||
memcpy(&length, bytes + offset, 4)
|
|
||||||
offset += 4
|
|
||||||
var i: Int32 = 0
|
|
||||||
while i < length {
|
|
||||||
var stringLength: Int32 = 0
|
|
||||||
memcpy(&stringLength, bytes + offset, 4)
|
|
||||||
offset += 4 + Int(stringLength)
|
|
||||||
i += 1
|
|
||||||
}
|
}
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
case .ObjectDictionary:
|
||||||
|
var length: Int32 = 0
|
||||||
|
memcpy(&length, bytes + offset, 4)
|
||||||
|
offset += 4
|
||||||
|
var i: Int32 = 0
|
||||||
|
while i < length {
|
||||||
|
var keyLength: Int32 = 0
|
||||||
|
memcpy(&keyLength, bytes + (offset + 4), 4)
|
||||||
|
offset += 8 + Int(keyLength)
|
||||||
|
|
||||||
|
var valueLength: Int32 = 0
|
||||||
|
memcpy(&valueLength, bytes + (offset + 4), 4)
|
||||||
|
offset += 8 + Int(valueLength)
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
case .Bytes:
|
||||||
|
var length: Int32 = 0
|
||||||
|
memcpy(&length, bytes + offset, 4)
|
||||||
|
offset += 4 + Int(length)
|
||||||
|
case .Nil:
|
||||||
|
break
|
||||||
|
case .StringArray, .BytesArray:
|
||||||
|
var length: Int32 = 0
|
||||||
|
memcpy(&length, bytes + offset, 4)
|
||||||
|
offset += 4
|
||||||
|
var i: Int32 = 0
|
||||||
|
while i < length {
|
||||||
|
var stringLength: Int32 = 0
|
||||||
|
memcpy(&stringLength, bytes + offset, 4)
|
||||||
|
offset += 4 + Int(stringLength)
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private class func positionOnKey(_ rawBytes: UnsafeRawPointer, offset: inout Int, maxOffset: Int, length: Int, key: String, valueType: ValueType) -> Bool {
|
private class func positionOnKey(_ rawBytes: UnsafeRawPointer, offset: inout Int, maxOffset: Int, length: Int, key: String, valueType: ValueType) -> Bool {
|
||||||
@ -815,7 +821,9 @@ public final class PostboxDecoder {
|
|||||||
if keyLength != Int(readKeyLength) {
|
if keyLength != Int(readKeyLength) {
|
||||||
/*let keyString = String(data: Data(bytes: bytes + (offset - Int(readKeyLength) - 1), count: Int(readKeyLength)), encoding: .utf8)
|
/*let keyString = String(data: Data(bytes: bytes + (offset - Int(readKeyLength) - 1), count: Int(readKeyLength)), encoding: .utf8)
|
||||||
print("\(String(describing: keyString))")*/
|
print("\(String(describing: keyString))")*/
|
||||||
skipValue(bytes, offset: &offset, length: length, valueType: ValueType(rawValue: readValueType)!)
|
if !skipValue(bytes, offset: &offset, length: length, valueType: ValueType(rawValue: readValueType)!) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -829,7 +837,9 @@ public final class PostboxDecoder {
|
|||||||
} else if readValueType == ValueType.Nil.rawValue {
|
} else if readValueType == ValueType.Nil.rawValue {
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
skipValue(bytes, offset: &offset, length: length, valueType: ValueType(rawValue: readValueType)!)
|
if !skipValue(bytes, offset: &offset, length: length, valueType: ValueType(rawValue: readValueType)!) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if !consumeKey {
|
if !consumeKey {
|
||||||
@ -839,7 +849,9 @@ public final class PostboxDecoder {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
skipValue(bytes, offset: &offset, length: length, valueType: ValueType(rawValue: readValueType)!)
|
if !skipValue(bytes, offset: &offset, length: length, valueType: ValueType(rawValue: readValueType)!) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -877,10 +889,14 @@ public final class PostboxDecoder {
|
|||||||
} else if readValueType == ValueType.Nil.rawValue {
|
} else if readValueType == ValueType.Nil.rawValue {
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
skipValue(bytes, offset: &offset, length: length, valueType: ValueType(rawValue: readValueType)!)
|
if !skipValue(bytes, offset: &offset, length: length, valueType: ValueType(rawValue: readValueType)!) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
skipValue(bytes, offset: &offset, length: length, valueType: ValueType(rawValue: readValueType)!)
|
if !skipValue(bytes, offset: &offset, length: length, valueType: ValueType(rawValue: readValueType)!) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -909,7 +925,9 @@ public final class PostboxDecoder {
|
|||||||
offset += 1
|
offset += 1
|
||||||
|
|
||||||
if readValueType != valueType.rawValue || keyLength != Int(readKeyLength) || memcmp(bytes + (offset - Int(readKeyLength) - 1), &keyValue, keyLength) != 0 {
|
if readValueType != valueType.rawValue || keyLength != Int(readKeyLength) || memcmp(bytes + (offset - Int(readKeyLength) - 1), &keyValue, keyLength) != 0 {
|
||||||
skipValue(bytes, offset: &offset, length: length, valueType: ValueType(rawValue: readValueType)!)
|
if !skipValue(bytes, offset: &offset, length: length, valueType: ValueType(rawValue: readValueType)!) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -1105,7 +1123,9 @@ public final class PostboxDecoder {
|
|||||||
return (innerData, .Object(hash: hash))
|
return (innerData, .Object(hash: hash))
|
||||||
} else {
|
} else {
|
||||||
let initialOffset = self.offset
|
let initialOffset = self.offset
|
||||||
PostboxDecoder.skipValue(self.buffer.memory.assumingMemoryBound(to: Int8.self), offset: &self.offset, length: self.buffer.length, valueType: actualValueType)
|
if !PostboxDecoder.skipValue(self.buffer.memory.assumingMemoryBound(to: Int8.self), offset: &self.offset, length: self.buffer.length, valueType: actualValueType) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
let data = ReadBuffer(memory: UnsafeMutableRawPointer(mutating: self.buffer.memory.advanced(by: initialOffset)), length: self.offset - initialOffset, freeWhenDone: false).makeData()
|
let data = ReadBuffer(memory: UnsafeMutableRawPointer(mutating: self.buffer.memory.advanced(by: initialOffset)), length: self.offset - initialOffset, freeWhenDone: false).makeData()
|
||||||
|
|
||||||
|
@ -562,9 +562,7 @@ public final class CachedChannelData: CachedPeerData {
|
|||||||
|
|
||||||
self.sendAsPeerId = decoder.decodeOptionalInt64ForKey("sendAsPeerId").flatMap(PeerId.init)
|
self.sendAsPeerId = decoder.decodeOptionalInt64ForKey("sendAsPeerId").flatMap(PeerId.init)
|
||||||
|
|
||||||
if let allowedReactions = decoder.decodeArray([MessageReaction.Reaction].self, forKey: "allowedReactionList") {
|
if let allowedReactions = decoder.decodeOptionalStringArrayForKey("allowedReactions") {
|
||||||
self.allowedReactions = allowedReactions
|
|
||||||
} else if let allowedReactions = decoder.decodeOptionalStringArrayForKey("allowedReactions") {
|
|
||||||
self.allowedReactions = allowedReactions.map(MessageReaction.Reaction.builtin)
|
self.allowedReactions = allowedReactions.map(MessageReaction.Reaction.builtin)
|
||||||
} else {
|
} else {
|
||||||
self.allowedReactions = nil
|
self.allowedReactions = nil
|
||||||
@ -715,9 +713,16 @@ public final class CachedChannelData: CachedPeerData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let allowedReactions = self.allowedReactions {
|
if let allowedReactions = self.allowedReactions {
|
||||||
encoder.encodeArray(allowedReactions, forKey: "allowedReactionList")
|
encoder.encodeStringArray(allowedReactions.compactMap { item -> String? in
|
||||||
|
switch item {
|
||||||
|
case let .builtin(value):
|
||||||
|
return value
|
||||||
|
case .custom:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}, forKey: "allowedReactions")
|
||||||
} else {
|
} else {
|
||||||
encoder.encodeNil(forKey: "allowedReactionList")
|
encoder.encodeNil(forKey: "allowedReactions")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,9 +180,7 @@ public final class CachedGroupData: CachedPeerData {
|
|||||||
|
|
||||||
self.inviteRequestsPending = decoder.decodeOptionalInt32ForKey("irp")
|
self.inviteRequestsPending = decoder.decodeOptionalInt32ForKey("irp")
|
||||||
|
|
||||||
if let allowedReactions = decoder.decodeArray([MessageReaction.Reaction].self, forKey: "allowedReactionList") {
|
if let allowedReactions = decoder.decodeOptionalStringArrayForKey("allowedReactions") {
|
||||||
self.allowedReactions = allowedReactions
|
|
||||||
} else if let allowedReactions = decoder.decodeOptionalStringArrayForKey("allowedReactions") {
|
|
||||||
self.allowedReactions = allowedReactions.map(MessageReaction.Reaction.builtin)
|
self.allowedReactions = allowedReactions.map(MessageReaction.Reaction.builtin)
|
||||||
} else {
|
} else {
|
||||||
self.allowedReactions = nil
|
self.allowedReactions = nil
|
||||||
@ -279,9 +277,16 @@ public final class CachedGroupData: CachedPeerData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let allowedReactions = self.allowedReactions {
|
if let allowedReactions = self.allowedReactions {
|
||||||
encoder.encodeArray(allowedReactions, forKey: "allowedReactionList")
|
encoder.encodeStringArray(allowedReactions.compactMap { item -> String? in
|
||||||
|
switch item {
|
||||||
|
case let .builtin(value):
|
||||||
|
return value
|
||||||
|
case .custom:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}, forKey: "allowedReactions")
|
||||||
} else {
|
} else {
|
||||||
encoder.encodeNil(forKey: "allowedReactionList")
|
encoder.encodeNil(forKey: "allowedReactions")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user