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

Commit ac166cfe authored by Jan Sebechlebsky's avatar Jan Sebechlebsky
Browse files

Fix crash when there's unexpected non-YUV buffer input.

The lockYCbCr returns NO_ERROR when called on non-YUV buffer,
but all pointers in android_ycbcr are set to null.

Check that the buffer has expected pixel format and fail early
(and gracefully) when it doesn't.

Bug: 301023410
Test: atest VirtualCameraTest (modified)
Change-Id: I5af39c3d844392eac02f32ee55a50a2a2899466b
parent c5181a5f
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -386,6 +386,13 @@ ndk::ScopedAStatus VirtualCameraRenderThread::renderIntoBlobStreamBuffer(
  bool compressionSuccess = true;
  if (gBuffer != nullptr) {
    android_ycbcr ycbcr;
    if (gBuffer->getPixelFormat() != HAL_PIXEL_FORMAT_YCbCr_420_888) {
      ALOGE("%s: Cannot compress non-YUV buffer (pixelFormat %d)", __func__,
            gBuffer->getPixelFormat());
      AHardwareBuffer_unlock(hwBuffer.get(), nullptr);
      return cameraStatus(Status::INTERNAL_ERROR);
    }

    status_t status =
        gBuffer->lockYCbCr(AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN, &ycbcr);
    ALOGV("Locked buffers");