Skip to content
Snippets Groups Projects
Commit 95d37da3 authored by Raphael Kim's avatar Raphael Kim Committed by Android (Google) Code Review
Browse files

Merge "[CDM] Handle empty and malformatted payloads for CDM backup restoration." into main

parents 709a358c a6bc4452
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment