Skip to content

Commit 608524d

Browse files
author
Steven Moreland
committed
libbinder: Parcel: grow rejects large data pos
This is unexpected behavior so throw an error. Allocating this much memory may cause OOM or other issues. Bug: 370831157 Test: fuzzer Change-Id: Iea0884ca61b08e52e6a6e9c66693e427cb5536f4
1 parent ff7e454 commit 608524d

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

libs/binder/Parcel.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2948,6 +2948,14 @@ status_t Parcel::growData(size_t len)
29482948
return BAD_VALUE;
29492949
}
29502950

2951+
if (mDataPos > mDataSize) {
2952+
// b/370831157 - this case used to abort. We also don't expect mDataPos < mDataSize, but
2953+
// this would only waste a bit of memory, so it's okay.
2954+
ALOGE("growData only expected at the end of a Parcel. pos: %zu, size: %zu, capacity: %zu",
2955+
mDataPos, len, mDataCapacity);
2956+
return BAD_VALUE;
2957+
}
2958+
29512959
if (len > SIZE_MAX - mDataSize) return NO_MEMORY; // overflow
29522960
if (mDataSize + len > SIZE_MAX / 3) return NO_MEMORY; // overflow
29532961
size_t newSize = ((mDataSize+len)*3)/2;

0 commit comments

Comments
 (0)