Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a6bc4452 authored by Raphael Kim's avatar Raphael Kim
Browse files

[CDM] Handle empty and malformatted payloads for CDM backup restoration.

Bug: 328345545
Test: atest CtsCompanionDeviceManagerCoreTestCases:BackupAndRestoreTest
Change-Id: I3b8b9c871a6955309d83b1b6aaa3bbe5b8ea98ba
parent 6f3e962d
Loading
Loading
Loading
Loading
+22 −6
Original line number Diff line number Diff line
@@ -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;
        }

        // 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
        byte[] associationsPayload = new byte[buffer.getInt()];
            associationsPayload = new byte[buffer.getInt()];
            buffer.get(associationsPayload);
        final Associations restoredAssociations = readAssociationsFromPayload(
                associationsPayload, userId);

            // Read the bytes containing backed-up system data transfer requests user consent
        byte[] requestsPayload = new byte[buffer.getInt()];
            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);

        List<SystemDataTransferRequest> restoredRequestsForUser =
                mSystemDataTransferRequestStore.readRequestsFromPayload(requestsPayload, userId);