Camera: memcpy Blob header rather than directly writing fields
The CameraBlob embedded in the output bitstream may not be word aligned.
Directly casting a byte* to a CameraBlob and assigning its field could
cause alignment exception.
Use memcpy from a CameraBlob struct instead.
Test: Partner tested on 32-bit system
Bug: 260045056
Change-Id: I34b6ba8ded458b2dc59638a50237b7a1f64bfb86
diff --git a/services/camera/libcameraservice/api2/HeicCompositeStream.cpp b/services/camera/libcameraservice/api2/HeicCompositeStream.cpp
index 54cc27a..237ce5e 100644
--- a/services/camera/libcameraservice/api2/HeicCompositeStream.cpp
+++ b/services/camera/libcameraservice/api2/HeicCompositeStream.cpp
@@ -1161,11 +1161,13 @@
inputFrame.fileFd = -1;
// Fill in HEIC header
- uint8_t *header = static_cast<uint8_t*>(dstBuffer) + mMaxHeicBufferSize - sizeof(CameraBlob);
- CameraBlob *blobHeader = (CameraBlob *)header;
// Must be in sync with CAMERA3_HEIC_BLOB_ID in android_media_Utils.cpp
- blobHeader->blobId = static_cast<CameraBlobId>(0x00FE);
- blobHeader->blobSizeBytes = fSize;
+ uint8_t *header = static_cast<uint8_t*>(dstBuffer) + mMaxHeicBufferSize - sizeof(CameraBlob);
+ CameraBlob blobHeader = {
+ .blobId = static_cast<CameraBlobId>(0x00FE),
+ .blobSizeBytes = static_cast<int32_t>(fSize)
+ };
+ memcpy(header, &blobHeader, sizeof(CameraBlob));
res = native_window_set_buffers_timestamp(mOutputSurface.get(), inputFrame.timestamp);
if (res != OK) {