Skip to content

Commit

Permalink
Drop message bodies longer than 2048 bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-signal authored Nov 18, 2024
1 parent 53966a5 commit bd4fa8c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions SignalServiceKit/Messages/MessageReceiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,11 @@ public final class MessageReceiver {
return nil
}

guard dataMessage.body?.utf8.count ?? 0 <= kOversizeTextMessageSizeThreshold else {
Logger.error("Dropping message with too large body: \(dataMessage.body?.utf8.count ?? 0)")
return nil
}

let body = dataMessage.body
let bodyRanges = dataMessage.bodyRanges.isEmpty ? nil : MessageBodyRanges(protos: dataMessage.bodyRanges)
let serverGuid = envelope.envelope.serverGuid.flatMap { UUID(uuidString: $0) }
Expand Down
2 changes: 1 addition & 1 deletion SignalUI/Views/BodyRanges/BodyRangesTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ extension BodyRangesTextView {
editableBody.endEditing()
} else if let string = UIPasteboard.general.strings?.first {
editableBody.beginEditing()
editableBody.replaceCharacters(in: selectedRange, with: string, selectedRange: selectedRange)
editableBody.replaceCharacters(in: selectedRange, with: StringSanitizer.sanitize(string), selectedRange: selectedRange)
editableBody.endEditing()
// Put the selection at the end of the new range.
self.selectedRange = NSRange(location: selectedRange.location + (string as NSString).length, length: 0)
Expand Down

0 comments on commit bd4fa8c

Please sign in to comment.