OSDN Git Service

Disallow reading object data from Parcels with non-object reads
authorMichael Wachenschwanz <mwachens@google.com>
Sat, 18 Nov 2017 02:25:05 +0000 (18:25 -0800)
committerandroid-build-team Robot <android-build-team-robot@google.com>
Fri, 10 Aug 2018 20:28:24 +0000 (20:28 +0000)
commit5f35052c5f4f7f92e637460ed2651675e0d0821a
tree99f46c50a5408f2005d318b263108f7b9d76567a
parent5df681db00cdc7dac638611f3fe76076290d78b2
Disallow reading object data from Parcels with non-object reads

The check added to each non-object reads adds an overhead. If the
objects (binders and file descriptors) were written to the Parcel in
sequential order then check adds a small O(1) overhead to each read,
plus an O(N) overhead to the first read (to verify the N objects were
added in order).
If the objects were written out of order (as in by jumping around the Parcel
with setDataPosition and writing Binder, DON'T DO THIS!!) (writing non
objects out of order is fine), the first read is forced to sort the objects
in the internal bookkeeping. Based on the assumption non sequential writes
are infrequent and overall Parcels are probably mostly sorted, insertion
sort was used. Worst case sorts will add an O(N^2) overhead to the first
non object read from the Parcel.

Test: run cts -m CtsOsTestCases -t android.os.cts.ParcelTest

Bug: 29833520
Change-Id: I82de8eb5f5eb56f869542d5358e96884c24301b2
(cherry picked from commit c517681c66a1a387be657e0cf06da8d19659dd14)
libs/binder/Parcel.cpp
libs/binder/include/binder/Parcel.h