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

Commit 81a7d0bf authored by Eino-Ville Talvala's avatar Eino-Ville Talvala Committed by Android Git Automerger
Browse files

am c639f06e: am 40c33635: Merge "CameraMetadata: Add sanity check to avoid...

am c639f06e: am 40c33635: Merge "CameraMetadata: Add sanity check to avoid accidental memory corruption." into mnc-dev

* commit 'c639f06e':
  CameraMetadata: Add sanity check to avoid accidental memory corruption.
parents 8f4994c9 c639f06e
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -289,6 +289,17 @@ status_t CameraMetadata::updateImpl(uint32_t tag, const void *data,
        ALOGE("%s: Tag %d not found", __FUNCTION__, tag);
        return BAD_VALUE;
    }
    // Safety check - ensure that data isn't pointing to this metadata, since
    // that would get invalidated if a resize is needed
    size_t bufferSize = get_camera_metadata_size(mBuffer);
    uintptr_t bufAddr = reinterpret_cast<uintptr_t>(mBuffer);
    uintptr_t dataAddr = reinterpret_cast<uintptr_t>(data);
    if (dataAddr > bufAddr && dataAddr < (bufAddr + bufferSize)) {
        ALOGE("%s: Update attempted with data from the same metadata buffer!",
                __FUNCTION__);
        return INVALID_OPERATION;
    }

    size_t data_size = calculate_camera_metadata_entry_data_size(type,
            data_count);