libbinder Parcel: Fix ubsan error in readData
Use don't cast the result of readInplace before calling memcpy to align
the data. With clang-r522817 passing an unaligned pointer to memcpy also
triggers a ubsan error.
Bug: 354981705
Change-Id: Ibd104bcfac519211857f1e9e93a1ec35e7bcd773
diff --git a/libs/binder/include/binder/Parcel.h b/libs/binder/include/binder/Parcel.h
index c394ac7..15a0da7 100644
--- a/libs/binder/include/binder/Parcel.h
+++ b/libs/binder/include/binder/Parcel.h
@@ -1240,7 +1240,7 @@
if (__builtin_mul_overflow(size, sizeof(T), &dataLen)) {
return -EOVERFLOW;
}
- auto data = reinterpret_cast<const T*>(readInplace(dataLen));
+ auto data = readInplace(dataLen);
if (data == nullptr) return BAD_VALUE;
// std::vector::insert and similar methods will require type-dependent
// byte alignment when inserting from a const iterator such as `data`,