Clients to avoid sending payloads larger than the maximum allowed size

Summary: ^

Reviewed By: passy

Differential Revision: D48645400

fbshipit-source-id: ac262296f113298812803c12eccf5a37da1da2b7
This commit is contained in:
Lorenzo Blasa
2023-08-24 10:05:17 -07:00
committed by Facebook GitHub Bot
parent 865d551f8e
commit ecc50f47e8
2 changed files with 15 additions and 0 deletions

View File

@@ -121,6 +121,14 @@ void FlipperWebSocket::send(
if (socket_ == NULL) {
return;
}
// Ensure the payload size is valid before sending.
// The maximum allowed size for a message payload is 2^53 - 1. But that is
// for the entire message, including any additional metadata.
if (message.length() > pow(2, 53) - 1) {
throw std::length_error("Payload is too big to send");
}
NSString* messageObjc = [NSString stringWithUTF8String:message.c_str()];
[socket_ send:messageObjc
withCompletionHandler:^(NSError*) {