Skip to content

Commit

Permalink
Clients to avoid sending payloads larger than the maximum allowed size
Browse files Browse the repository at this point in the history
Summary: ^

Reviewed By: passy

Differential Revision: D48645400

fbshipit-source-id: ac262296f113298812803c12eccf5a37da1da2b7
  • Loading branch information
lblasa authored and facebook-github-bot committed Aug 24, 2023
1 parent 865d551 commit ecc50f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions android/src/main/cpp/sonar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,13 @@ class JFlipperWebSocket : public facebook::flipper::FlipperSocket {
if (socket_ == nullptr) {
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");
}

socket_->send(message);
completion();
}
Expand Down
8 changes: 8 additions & 0 deletions iOS/FlipperKit/FlipperWebSocket.mm
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@
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*) {
Expand Down

0 comments on commit ecc50f4

Please sign in to comment.