Custom Anbox installation files & patches, including patched Android OS image file.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
3.1 KiB

4 years ago
  1. From 7775f90af395fb122a2600b6706f002d55b3b9db Mon Sep 17 00:00:00 2001
  2. From: Antoine Fontaine <antoine.fontaine@epfl.ch>
  3. Date: Tue, 2 Jun 2020 10:36:21 +0200
  4. Subject: [PATCH] rpc: use ByteSizeLong from protobuf
  5. ByteSize() is deperecated, and BiteSizeLong() returns a size_t already,
  6. which is what we use. This way, we also avoid potential overflows when
  7. casting to int back and from.
  8. ---
  9. src/anbox/rpc/channel.cpp | 7 +++----
  10. src/anbox/rpc/message_processor.cpp | 4 ++--
  11. 2 files changed, 5 insertions(+), 6 deletions(-)
  12. diff --git a/src/anbox/rpc/channel.cpp b/src/anbox/rpc/channel.cpp
  13. index b0c2eada3..581937f6c 100644
  14. --- a/src/anbox/rpc/channel.cpp
  15. +++ b/src/anbox/rpc/channel.cpp
  16. @@ -43,7 +43,7 @@ void Channel::call_method(std::string const &method_name,
  17. }
  18. void Channel::send_event(google::protobuf::MessageLite const &event) {
  19. - VariableLengthArray<2048> buffer{static_cast<size_t>(event.ByteSize())};
  20. + VariableLengthArray<2048> buffer{event.ByteSizeLong()};
  21. event.SerializeWithCachedSizesToArray(buffer.data());
  22. anbox::protobuf::rpc::Result response;
  23. @@ -55,8 +55,7 @@ void Channel::send_event(google::protobuf::MessageLite const &event) {
  24. protobuf::rpc::Invocation Channel::invocation_for(
  25. std::string const &method_name,
  26. google::protobuf::MessageLite const *request) {
  27. - anbox::VariableLengthArray<2048> buffer{
  28. - static_cast<size_t>(request->ByteSize())};
  29. + anbox::VariableLengthArray<2048> buffer{request->ByteSizeLong()};
  30. request->SerializeWithCachedSizesToArray(buffer.data());
  31. @@ -72,7 +71,7 @@ protobuf::rpc::Invocation Channel::invocation_for(
  32. void Channel::send_message(const std::uint8_t &type,
  33. google::protobuf::MessageLite const &message) {
  34. - const size_t size = message.ByteSize();
  35. + const size_t size = message.ByteSizeLong();
  36. const unsigned char header_bytes[header_size] = {
  37. static_cast<unsigned char>((size >>16) & 0xff),
  38. static_cast<unsigned char>((size >> 8) & 0xff),
  39. diff --git a/src/anbox/rpc/message_processor.cpp b/src/anbox/rpc/message_processor.cpp
  40. index ba25a5a9f..31cea883f 100644
  41. --- a/src/anbox/rpc/message_processor.cpp
  42. +++ b/src/anbox/rpc/message_processor.cpp
  43. @@ -87,7 +87,7 @@ bool MessageProcessor::process_data(const std::vector<std::uint8_t> &data) {
  44. void MessageProcessor::send_response(::google::protobuf::uint32 id,
  45. google::protobuf::MessageLite *response) {
  46. VariableLengthArray<serialization_buffer_size> send_response_buffer(
  47. - static_cast<size_t>(response->ByteSize()));
  48. + response->ByteSizeLong());
  49. response->SerializeWithCachedSizesToArray(send_response_buffer.data());
  50. @@ -96,7 +96,7 @@ void MessageProcessor::send_response(::google::protobuf::uint32 id,
  51. send_response_result.set_response(send_response_buffer.data(),
  52. send_response_buffer.size());
  53. - send_response_buffer.resize(send_response_result.ByteSize());
  54. + send_response_buffer.resize(send_response_result.ByteSizeLong());
  55. send_response_result.SerializeWithCachedSizesToArray(
  56. send_response_buffer.data());