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

Commit 1b1dcd42 authored by Vignesh Venkatasubramanian's avatar Vignesh Venkatasubramanian
Browse files

heif: Clamp display height and display width

The earlier code clamped the value of display width and display
height in FrameDecoder.cpp. This approach was incorrect because
display width and display height are allowed to be greater than
width and height respectively when being called from
MediaMetadataRetriever.getScaledFrameAtTime. It was causing the
cts tests to fail.

The correct fix is to clamp them in the HeifDecoder since the
original set of changes were to support cropping in Heif.

Bug: 316481431, 320331874
Test: atest android.security.cts.StagefrightTest CtsMediaMiscTestCases
Change-Id: I5d0fcd70a81c9d429f175b4ca529a2554f4f9883
parent 89588107
Loading
Loading
Loading
Loading
+8 −2
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@
#include <private/media/VideoFrame.h>
#include <private/media/VideoFrame.h>
#include <utils/Log.h>
#include <utils/Log.h>
#include <utils/RefBase.h>
#include <utils/RefBase.h>
#include <algorithm>
#include <vector>
#include <vector>


HeifDecoder* createHeifDecoder() {
HeifDecoder* createHeifDecoder() {
@@ -42,7 +43,10 @@ namespace android {


void initFrameInfo(HeifFrameInfo *info, const VideoFrame *videoFrame) {
void initFrameInfo(HeifFrameInfo *info, const VideoFrame *videoFrame) {
    info->mWidth = videoFrame->mDisplayWidth;
    info->mWidth = videoFrame->mDisplayWidth;
    info->mHeight = videoFrame->mDisplayHeight;
    // Number of scanlines is mDisplayHeight. Clamp it to mHeight to guard
    // against malformed streams claiming that mDisplayHeight is greater than
    // mHeight.
    info->mHeight = std::min(videoFrame->mDisplayHeight, videoFrame->mHeight);
    info->mRotationAngle = videoFrame->mRotationAngle;
    info->mRotationAngle = videoFrame->mRotationAngle;
    info->mBytesPerPixel = videoFrame->mBytesPerPixel;
    info->mBytesPerPixel = videoFrame->mBytesPerPixel;
    info->mDurationUs = videoFrame->mDurationUs;
    info->mDurationUs = videoFrame->mDurationUs;
@@ -746,7 +750,9 @@ bool HeifDecoderImpl::getScanlineInner(uint8_t* dst) {
                   (videoFrame->mRowBytes * (mCurScanline + videoFrame->mDisplayTop)) +
                   (videoFrame->mRowBytes * (mCurScanline + videoFrame->mDisplayTop)) +
                   (videoFrame->mBytesPerPixel * videoFrame->mDisplayLeft);
                   (videoFrame->mBytesPerPixel * videoFrame->mDisplayLeft);
    mCurScanline++;
    mCurScanline++;
    memcpy(dst, src, videoFrame->mBytesPerPixel * videoFrame->mDisplayWidth);
    // Do not try to copy more than |videoFrame->mWidth| pixels.
    uint32_t width = std::min(videoFrame->mDisplayWidth, videoFrame->mWidth);
    memcpy(dst, src, videoFrame->mBytesPerPixel * width);
    return true;
    return true;
}
}


+0 −7
Original line number Original line Diff line number Diff line
@@ -102,13 +102,6 @@ sp<IMemory> allocVideoFrame(const sp<MetaData>& trackMeta,
            displayTop = 0;
            displayTop = 0;
        }
        }
    }
    }
    if (displayWidth > width) {
        displayWidth = width;
    }
    if (displayHeight > height) {
        displayHeight = height;
    }



    if (allocRotated) {
    if (allocRotated) {
        if (rotationAngle == 90 || rotationAngle == 270) {
        if (rotationAngle == 90 || rotationAngle == 270) {