summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Wright <michaelwr@google.com>2022-09-26 20:37:33 +0100
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-02-12 16:56:07 +0000
commitd7107c59aaf70a99fdefb106d297230b6531e5d2 (patch)
tree0c71fc5e5a9bef2e97b801847a2a02272423c87c
parent0c59b9aa61a75e743f80e14c249d81ed4bd59984 (diff)
downloadbase-d7107c59aaf70a99fdefb106d297230b6531e5d2.tar.gz
Reconcile WorkSource parcel and unparcel code.
Prior to this CL, WorkSources would Parcel their list of WorkChains as -1 if null, or the size of the list followed by the list itself if non-null. When reading it back in, on the other hand, they would check if the size was positive, and only then read the list from the Parcel. This works for all cases except when the WorkSource has an empty but non-null list of WorkChains as the list would get written to the parcel, but then never read on the other side. If parceling a list was a no-op when empty this wouldn't be an issue, but it must write at least its size into the parcel to know how many elements to extract. In the empty list case, this single element is left unread as the size is not positive which essentially corrupts any future items read from that same parcelable. Bug: 220302519 Test: atest android.security.cts.WorkSourceTest#testWorkChainParceling Change-Id: I2fec40dfced420ca38e717059b0e95ee8ef9946a (cherry picked from commit 266b3bddcf14d448c0972db64b42950f76c759e3) Merged-In: I2fec40dfced420ca38e717059b0e95ee8ef9946a
-rw-r--r--core/java/android/os/WorkSource.java2
1 files changed, 1 insertions, 1 deletions
diff --git a/core/java/android/os/WorkSource.java b/core/java/android/os/WorkSource.java
index e899f7729efa..65528e306943 100644
--- a/core/java/android/os/WorkSource.java
+++ b/core/java/android/os/WorkSource.java
@@ -128,7 +128,7 @@ public class WorkSource implements Parcelable {
mNames = in.createStringArray();
int numChains = in.readInt();
- if (numChains > 0) {
+ if (numChains >= 0) {
mChains = new ArrayList<>(numChains);
in.readParcelableList(mChains, WorkChain.class.getClassLoader(), android.os.WorkSource.WorkChain.class);
} else {