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

@@ -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();
}