diff options
| author | 2024-03-27 00:34:26 +0000 | |
|---|---|---|
| committer | 2024-03-27 00:34:26 +0000 | |
| commit | 95d37da3d3a38ba7befefaea08d43d864c09147a (patch) | |
| tree | afd60f489e02e2cc03dd27841bad972c3b359a2e | |
| parent | 709a358c1e08e5534a6b07ba6e35d3ec4716c82a (diff) | |
| parent | a6bc44527855e5e8637182bc1ca14e7630e64fbe (diff) | |
Merge "[CDM] Handle empty and malformatted payloads for CDM backup restoration." into main
| -rw-r--r-- | services/companion/java/com/android/server/companion/BackupRestoreProcessor.java | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/services/companion/java/com/android/server/companion/BackupRestoreProcessor.java b/services/companion/java/com/android/server/companion/BackupRestoreProcessor.java index 5e52e06248cb..82e9a26310e8 100644 --- a/services/companion/java/com/android/server/companion/BackupRestoreProcessor.java +++ b/services/companion/java/com/android/server/companion/BackupRestoreProcessor.java @@ -111,6 +111,11 @@ class BackupRestoreProcessor { Slog.i(TAG, "applyRestoredPayload() userId=[" + userId + "], payload size=[" + payload.length + "]."); + if (payload.length == 0) { + Slog.i(TAG, "CDM backup payload was empty."); + return; + } + ByteBuffer buffer = ByteBuffer.wrap(payload); // Make sure that payload version matches current version to ensure proper deserialization @@ -120,15 +125,26 @@ class BackupRestoreProcessor { return; } - // Read the bytes containing backed-up associations - byte[] associationsPayload = new byte[buffer.getInt()]; - buffer.get(associationsPayload); + // Pre-load the bytes into memory before processing them to ensure payload mal-formatting + // error is caught early on. + final byte[] associationsPayload; + final byte[] requestsPayload; + try { + // Read the bytes containing backed-up associations + associationsPayload = new byte[buffer.getInt()]; + buffer.get(associationsPayload); + + // Read the bytes containing backed-up system data transfer requests user consent + requestsPayload = new byte[buffer.getInt()]; + buffer.get(requestsPayload); + } catch (Exception bufferException) { + Slog.e(TAG, "CDM backup payload was mal-formatted.", bufferException); + return; + } + final Associations restoredAssociations = readAssociationsFromPayload( associationsPayload, userId); - // Read the bytes containing backed-up system data transfer requests user consent - byte[] requestsPayload = new byte[buffer.getInt()]; - buffer.get(requestsPayload); List<SystemDataTransferRequest> restoredRequestsForUser = mSystemDataTransferRequestStore.readRequestsFromPayload(requestsPayload, userId); |