Skip to content

Commit 58ef98e

Browse files
smore-loreaoleary
authored andcommitted
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 (cherry picked from commit 608524d462278c2c9f6716cd94f126c85e9f2e91) (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:e4f04ab7dff943d91240e02ebb2287278d1c40c1) Merged-In: Iea0884ca61b08e52e6a6e9c66693e427cb5536f4 Change-Id: Iea0884ca61b08e52e6a6e9c66693e427cb5536f4
1 parent 6118ae9 commit 58ef98e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

libs/binder/Parcel.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -2375,6 +2375,14 @@ status_t Parcel::growData(size_t len)
23752375
return BAD_VALUE;
23762376
}
23772377

2378+
if (mDataPos > mDataSize) {
2379+
// b/370831157 - this case used to abort. We also don't expect mDataPos < mDataSize, but
2380+
// this would only waste a bit of memory, so it's okay.
2381+
ALOGE("growData only expected at the end of a Parcel. pos: %zu, size: %zu, capacity: %zu",
2382+
mDataPos, len, mDataCapacity);
2383+
return BAD_VALUE;
2384+
}
2385+
23782386
if (len > SIZE_MAX - mDataSize) return NO_MEMORY; // overflow
23792387
if (mDataSize + len > SIZE_MAX / 3) return NO_MEMORY; // overflow
23802388
size_t newSize = ((mDataSize+len)*3)/2;

0 commit comments

Comments
 (0)