summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorChristopher Wiley2015-10-31 15:22:15 -0500
committerChristopher Wiley2015-10-31 15:35:32 -0500
commitf0fc52b59be0bf39912f7b698d9bde26415a6096 (patch)
tree0403cac00cec6a7843b87f84ef6399f233f118a5 /libs
parent8ebad13b340921a40a367c9f1808d0c26147e2a6 (diff)
downloadframeworks-native-f0fc52b59be0bf39912f7b698d9bde26415a6096.tar.gz
frameworks-native-f0fc52b59be0bf39912f7b698d9bde26415a6096.tar.xz
frameworks-native-f0fc52b59be0bf39912f7b698d9bde26415a6096.zip
Fix bug in byte vector serialization
Byte vectors are used by the generated C++ code as the representation of Java byte[]. This type is serialized as a packed byte array on the java side. Bug: 25012838 Test: integration tests for byte[] show this type crossing language boundaries correctly. Change-Id: I8bb1b8ffcb77ced44f99f6b370226a32694f7df1
Diffstat (limited to 'libs')
-rw-r--r--libs/binder/Parcel.cpp42
1 files changed, 20 insertions, 22 deletions
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index ab2cdab21..694916cf1 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -719,25 +719,25 @@ restart_write:
719 719
720status_t Parcel::writeByteVector(const std::vector<int8_t>& val) 720status_t Parcel::writeByteVector(const std::vector<int8_t>& val)
721{ 721{
722 status_t status;
722 if (val.size() > std::numeric_limits<int32_t>::max()) { 723 if (val.size() > std::numeric_limits<int32_t>::max()) {
723 return BAD_VALUE; 724 status = BAD_VALUE;
725 return status;
724 } 726 }
725 727
726 status_t status = writeInt32(val.size()); 728 status = writeInt32(val.size());
727
728 if (status != OK) { 729 if (status != OK) {
729 return status; 730 return status;
730 } 731 }
731 732
732 for (const auto& item : val) { 733 void* data = writeInplace(val.size());
733 status = writeByte(item); 734 if (!data) {
734 735 status = BAD_VALUE;
735 if (status != OK) { 736 return status;
736 return status;
737 }
738 } 737 }
739 738
740 return OK; 739 memcpy(data, val.data(), val.size());
740 return status;
741} 741}
742 742
743status_t Parcel::writeInt32Vector(const std::vector<int32_t>& val) 743status_t Parcel::writeInt32Vector(const std::vector<int32_t>& val)
@@ -1343,21 +1343,19 @@ status_t Parcel::readByteVector(std::vector<int8_t>* val) const {
1343 return status; 1343 return status;
1344 } 1344 }
1345 1345
1346 if (size < 0) { 1346 if (size < 0 || size_t(size) > dataAvail()) {
1347 return BAD_VALUE; 1347 status = BAD_VALUE;
1348 return status;
1348 } 1349 }
1349 1350 const void* data = readInplace(size);
1350 val->resize(size); 1351 if (!data) {
1351 1352 status = BAD_VALUE;
1352 for (auto& v : *val) { 1353 return status;
1353 status = readByte(&v);
1354
1355 if (status != OK) {
1356 return status;
1357 }
1358 } 1354 }
1355 val->resize(size);
1356 memcpy(val->data(), data, size);
1359 1357
1360 return OK; 1358 return status;
1361} 1359}
1362 1360
1363status_t Parcel::readInt32Vector(std::vector<int32_t>* val) const { 1361status_t Parcel::readInt32Vector(std::vector<int32_t>* val) const {