Properly handle too-large messages

1. Take note of any large messages.
2. If they are way too large, we just drop them on the floor.

// FREEBIE
This commit is contained in:
Michael Kirk 2017-07-26 14:48:49 -04:00
parent 0113bb2c11
commit 91ad2ec32b
4 changed files with 16 additions and 9 deletions

View File

@ -125,7 +125,7 @@ EXTERNAL SOURCES:
:branch: signal-master :branch: signal-master
:git: https://github.com/WhisperSystems/JSQMessagesViewController.git :git: https://github.com/WhisperSystems/JSQMessagesViewController.git
SignalServiceKit: SignalServiceKit:
:path: . :path: "."
SocketRocket: SocketRocket:
:git: https://github.com/facebook/SocketRocket.git :git: https://github.com/facebook/SocketRocket.git

View File

@ -113,7 +113,7 @@ EXTERNAL SOURCES:
AxolotlKit: AxolotlKit:
:git: https://github.com/WhisperSystems/SignalProtocolKit.git :git: https://github.com/WhisperSystems/SignalProtocolKit.git
SignalServiceKit: SignalServiceKit:
:path: ../../../SignalServiceKit.podspec :path: "../../../SignalServiceKit.podspec"
SocketRocket: SocketRocket:
:git: https://github.com/facebook/SocketRocket.git :git: https://github.com/facebook/SocketRocket.git

View File

@ -333,6 +333,20 @@ NSString *const OWSMessageProcessingJobFinderExtensionGroup = @"OWSMessageProces
- (void)handleReceivedEnvelope:(OWSSignalServiceProtosEnvelope *)envelope - (void)handleReceivedEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
{ {
// Drop any too-large messages on the floor. Well behaving clients should never send them.
NSUInteger kMaxEnvelopeByteCount = 250 * 1024;
if (envelope.serializedSize > kMaxEnvelopeByteCount) {
OWSProdError(@"message_receiver_error_oversize_message");
return;
}
// Take note of any messages larger than we expect, but still process them.
// This likely indicates a misbehaving sending client.
NSUInteger kLargeEnvelopeWarningByteCount = 25 * 1024;
if (envelope.serializedSize > kLargeEnvelopeWarningByteCount) {
OWSProdError(@"message_receiver_error_large_message");
}
[self.processingQueue enqueueEnvelopeForProcessing:envelope]; [self.processingQueue enqueueEnvelopeForProcessing:envelope];
[self.processingQueue drainQueue]; [self.processingQueue drainQueue];
} }

View File

@ -392,13 +392,6 @@ NS_ASSUME_NONNULL_BEGIN
return; return;
} }
NSUInteger kMaxEncryptedDataLength = 250 * 1024;
if (encryptedData.length > kMaxEncryptedDataLength) {
OWSProdError(@"message_manager_error_oversize_message");
completion(nil);
return;
}
NSData *plaintextData; NSData *plaintextData;
@try { @try {