Skip to content

Commit

Permalink
Snap for 11733120 from dd09ef0 to 24Q3-release
Browse files Browse the repository at this point in the history
Change-Id: I23e3506b630c28c30a1139d94c9f97f0c4c915f5
  • Loading branch information
Android Build Coastguard Worker committed Apr 18, 2024
2 parents 91c2de7 + dd09ef0 commit 5b7ad60
Show file tree
Hide file tree
Showing 16 changed files with 230 additions and 151 deletions.
30 changes: 20 additions & 10 deletions media/aconfig/codec_fwk.aconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ flag {
bug: "201479783"
}

flag {
name: "set_state_early"
namespace: "codec_fwk"
description: "Bugfix flag for setting state early to avoid a race condition"
bug: "298613712"
metadata {
purpose: PURPOSE_BUGFIX
}
}

flag {
name: "dynamic_color_aspects"
is_exported: true
Expand Down Expand Up @@ -97,6 +87,26 @@ flag {
bug: "325549730"
}

flag {
name: "set_callback_stall"
namespace: "codec_fwk"
description: "Bugfix flag for setCallback stall"
bug: "326010604"
metadata {
purpose: PURPOSE_BUGFIX
}
}

flag {
name: "set_state_early"
namespace: "codec_fwk"
description: "Bugfix flag for setting state early to avoid a race condition"
bug: "298613711"
metadata {
purpose: PURPOSE_BUGFIX
}
}

flag {
name: "teamfood"
namespace: "codec_fwk"
Expand Down
9 changes: 6 additions & 3 deletions media/libmediaplayerservice/nuplayer/NuPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2098,9 +2098,12 @@ void NuPlayer::updateVideoSize(
displayHeight,
cropLeft, cropTop);
} else {
CHECK(inputFormat->findInt32("width", &displayWidth));
CHECK(inputFormat->findInt32("height", &displayHeight));

if (!inputFormat->findInt32("width", &displayWidth)
|| !inputFormat->findInt32("height", &displayHeight)) {
ALOGW("Either video width or video height missing, reporting 0x0!");
notifyListener(MEDIA_SET_VIDEO_SIZE, 0, 0);
return;
}
ALOGV("Video input format %d x %d", displayWidth, displayHeight);
}

Expand Down
99 changes: 51 additions & 48 deletions media/libstagefright/tests/fuzzers/FrameDecoderFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,61 +24,64 @@

namespace android {

#define MAX_MEDIA_BUFFER_SIZE 2048
static const android_pixel_format_t kColorFormats[] = {
HAL_PIXEL_FORMAT_RGBA_8888,
HAL_PIXEL_FORMAT_RGB_565,
HAL_PIXEL_FORMAT_BGRA_8888,
HAL_PIXEL_FORMAT_RGBA_1010102,
HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, /* To cover the default case */
};

// Fuzzer entry point.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
// Init our wrapper
FuzzedDataProvider fdp(data, size);
static const MediaSource::ReadOptions::SeekMode kSeekModes[] = {
MediaSource::ReadOptions::SeekMode::SEEK_PREVIOUS_SYNC,
MediaSource::ReadOptions::SeekMode::SEEK_NEXT_SYNC,
MediaSource::ReadOptions::SeekMode::SEEK_CLOSEST_SYNC,
MediaSource::ReadOptions::SeekMode::SEEK_CLOSEST,
MediaSource::ReadOptions::SeekMode::SEEK_FRAME_INDEX,
};

static const std::string kComponentNames[] = {
"c2.android.avc.decoder", "c2.android.hevc.decoder", "c2.android.vp8.decoder",
"c2.android.vp9.decoder", "c2.android.av1.decoder", "c2.android.mpeg4.decoder",
"c2.android.h263.decoder",
};

std::string name = fdp.ConsumeRandomLengthString(fdp.remaining_bytes());
AString componentName(name.c_str());
sp<MetaData> trackMeta = generateMetaData(&fdp);
sp<IMediaSource> source = new IMediaSourceFuzzImpl(&fdp, MAX_MEDIA_BUFFER_SIZE);
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
FuzzedDataProvider fdp(data, size);
std::string component = fdp.PickValueInArray(kComponentNames);
AString componentName(component.c_str());
sp<MetaData> trackMeta = generateMetaData(&fdp, component);
sp<IMediaSource> source = sp<IMediaSourceFuzzImpl>::make(&fdp, gMaxMediaBufferSize);

// Image or video Decoder?
sp<FrameDecoder> decoder;
bool isVideoDecoder = fdp.ConsumeBool();
if (isVideoDecoder) {
decoder = new VideoFrameDecoder(componentName, trackMeta, source);
sp<FrameDecoder> decoder = nullptr;
if (fdp.ConsumeBool()) {
decoder = sp<MediaImageDecoder>::make(componentName, trackMeta, source);
} else {
decoder = new MediaImageDecoder(componentName, trackMeta, source);
decoder = sp<VideoFrameDecoder>::make(componentName, trackMeta, source);
}

while (fdp.remaining_bytes()) {
uint8_t switchCase = fdp.ConsumeIntegralInRange<uint8_t>(0, 3);
switch (switchCase) {
case 0: {
int64_t frameTimeUs = fdp.ConsumeIntegral<int64_t>();
int option = fdp.ConsumeIntegral<int>();
int colorFormat = fdp.ConsumeIntegral<int>();
decoder->init(frameTimeUs, option, colorFormat);
break;
}
case 1:
decoder->extractFrame();
break;
case 2: {
FrameRect rect;
rect.left = fdp.ConsumeIntegral<int32_t>();
rect.top = fdp.ConsumeIntegral<int32_t>();
rect.right = fdp.ConsumeIntegral<int32_t>();
rect.bottom = fdp.ConsumeIntegral<int32_t>();
decoder->extractFrame(&rect);
break;
}
case 3: {
sp<MetaData> trackMeta = generateMetaData(&fdp);
decoder->getMetadataOnly(trackMeta,
/*colorFormat*/ fdp.ConsumeIntegral<int>(),
/*thumbnail*/ fdp.ConsumeBool());
break;
}
}
if (decoder.get() &&
decoder->init(fdp.ConsumeIntegral<uint64_t>() /* frameTimeUs */,
fdp.PickValueInArray(kSeekModes) /* option */,
fdp.PickValueInArray(kColorFormats) /* colorFormat */) == OK) {
auto frameDecoderAPI = fdp.PickValueInArray<const std::function<void()>>({
[&]() { decoder->extractFrame(); },
[&]() {
FrameRect rect(fdp.ConsumeIntegral<int32_t>() /* left */,
fdp.ConsumeIntegral<int32_t>() /* top */,
fdp.ConsumeIntegral<int32_t>() /* right */,
fdp.ConsumeIntegral<int32_t>() /* bottom */
);
decoder->extractFrame(&rect);
},
[&]() {
FrameDecoder::getMetadataOnly(
trackMeta, fdp.PickValueInArray(kColorFormats) /* colorFormat */,
fdp.ConsumeBool() /* thumbnail */);
},
});
frameDecoderAPI();
}

generated_mime_types.clear();

return 0;
}

Expand Down
147 changes: 89 additions & 58 deletions media/libstagefright/tests/fuzzers/FrameDecoderHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,69 +20,100 @@
#include <media/stagefright/MetaData.h>
#include "MediaMimeTypes.h"

#define MAX_METADATA_BUF_SIZE 512

namespace android {

std::vector<std::shared_ptr<char>> generated_mime_types;
constexpr uint8_t kMinKeyHeight = 32;
constexpr uint8_t kMinKeyWidth = 32;
constexpr uint16_t kMaxKeyHeight = 2160;
constexpr uint16_t kMaxKeyWidth = 3840;
size_t gMaxMediaBufferSize = 0;

sp<MetaData> generateMetaData(FuzzedDataProvider* fdp, std::string componentName = std::string()) {
sp<MetaData> newMeta = sp<MetaData>::make();

const char* mime;
if(!componentName.empty())
{
auto it = decoderToMediaType.find(componentName);
mime = it->second;
}
else{
size_t index = fdp->ConsumeIntegralInRange<size_t>(0, kMimeTypes.size());
// Let there be a chance of a true random string
if (index == kMimeTypes.size()) {
std::string mime_str = fdp->ConsumeRandomLengthString(64);
std::shared_ptr<char> mime_cstr(new char[mime_str.length()+1]);
generated_mime_types.push_back(mime_cstr);
strncpy(mime_cstr.get(), mime_str.c_str(), mime_str.length()+1);
mime = mime_cstr.get();
} else {
mime = kMimeTypes[index];
}
}
newMeta->setCString(kKeyMIMEType, mime);

auto height = fdp->ConsumeIntegralInRange<uint16_t>(kMinKeyHeight, kMaxKeyHeight);
auto width = fdp->ConsumeIntegralInRange<uint16_t>(kMinKeyWidth, kMaxKeyWidth);
newMeta->setInt32(kKeyHeight, height);
newMeta->setInt32(kKeyWidth, width);

gMaxMediaBufferSize = height * width;

if (fdp->ConsumeBool()) {
newMeta->setInt32(kKeyTileHeight,
fdp->ConsumeIntegralInRange<uint16_t>(kMinKeyHeight, height));
newMeta->setInt32(kKeyTileWidth,
fdp->ConsumeIntegralInRange<uint16_t>(kMinKeyWidth, width));
newMeta->setInt32(kKeyGridRows, fdp->ConsumeIntegral<uint8_t>());
newMeta->setInt32(kKeyGridCols, fdp->ConsumeIntegral<uint8_t>());
}

if (fdp->ConsumeBool()) {
newMeta->setInt32(kKeySARHeight, fdp->ConsumeIntegral<uint8_t>());
newMeta->setInt32(kKeySARWidth, fdp->ConsumeIntegral<uint8_t>());
}

if (fdp->ConsumeBool()) {
newMeta->setInt32(kKeyDisplayHeight,
fdp->ConsumeIntegralInRange<uint16_t>(height, UINT16_MAX));
newMeta->setInt32(kKeyDisplayWidth,
fdp->ConsumeIntegralInRange<uint16_t>(width, UINT16_MAX));
}

if (fdp->ConsumeBool()) {
newMeta->setRect(kKeyCropRect, fdp->ConsumeIntegral<int32_t>() /* left */,
fdp->ConsumeIntegral<int32_t>() /* top */,
fdp->ConsumeIntegral<int32_t>() /* right */,
fdp->ConsumeIntegral<int32_t>() /* bottom */);
}

if (fdp->ConsumeBool()) {
newMeta->setInt32(kKeyRotation, fdp->ConsumeIntegralInRange<uint8_t>(0, 3) * 90);
}

if (fdp->ConsumeBool()) {
newMeta->setInt64(kKeyThumbnailTime, fdp->ConsumeIntegral<uint64_t>());
newMeta->setInt32(kKeyThumbnailHeight, fdp->ConsumeIntegral<uint8_t>());
newMeta->setInt32(kKeyThumbnailWidth, fdp->ConsumeIntegral<uint8_t>());

size_t thumbnailSize = fdp->ConsumeIntegral<size_t>();
std::vector<uint8_t> thumbnailData = fdp->ConsumeBytes<uint8_t>(thumbnailSize);
if (mime == MEDIA_MIMETYPE_VIDEO_AV1) {
newMeta->setData(kKeyThumbnailAV1C, fdp->ConsumeIntegral<int32_t>() /* type */,
thumbnailData.data(), thumbnailData.size());
} else {
newMeta->setData(kKeyThumbnailHVCC, fdp->ConsumeIntegral<int32_t>() /* type */,
thumbnailData.data(), thumbnailData.size());
}
}

sp<MetaData> generateMetaData(FuzzedDataProvider *fdp) {
sp<MetaData> newMeta = new MetaData();

// random MIME Type
const char *mime_type;
size_t index = fdp->ConsumeIntegralInRange<size_t>(0, kMimeTypes.size());
// Let there be a chance of a true random string
if (index == kMimeTypes.size()) {
std::string mime_str = fdp->ConsumeRandomLengthString(64);
std::shared_ptr<char> mime_cstr(new char[mime_str.length()+1]);
generated_mime_types.push_back(mime_cstr);
strncpy(mime_cstr.get(), mime_str.c_str(), mime_str.length()+1);
mime_type = mime_cstr.get();
} else {
mime_type = kMimeTypes[index];
if (fdp->ConsumeBool()) {
size_t profileSize = fdp->ConsumeIntegral<size_t>();
std::vector<uint8_t> profileData = fdp->ConsumeBytes<uint8_t>(profileSize);
newMeta->setData(kKeyIccProfile, fdp->ConsumeIntegral<int32_t>() /* type */,
profileData.data(), profileData.size());
}
newMeta->setCString(kKeyMIMEType, mime_type);

// Thumbnail time
newMeta->setInt64(kKeyThumbnailTime, fdp->ConsumeIntegral<int64_t>());

// Values used by allocVideoFrame
newMeta->setInt32(kKeyRotation, fdp->ConsumeIntegral<int32_t>());
size_t profile_size =
fdp->ConsumeIntegralInRange<size_t>(0, MAX_METADATA_BUF_SIZE);
std::vector<uint8_t> profile_bytes =
fdp->ConsumeBytes<uint8_t>(profile_size);
newMeta->setData(kKeyIccProfile,
fdp->ConsumeIntegral<int32_t>(),
profile_bytes.empty() ? nullptr : profile_bytes.data(),
profile_bytes.size());
newMeta->setInt32(kKeySARWidth, fdp->ConsumeIntegral<int32_t>());
newMeta->setInt32(kKeySARHeight, fdp->ConsumeIntegral<int32_t>());
newMeta->setInt32(kKeyDisplayWidth, fdp->ConsumeIntegral<int32_t>());
newMeta->setInt32(kKeyDisplayHeight, fdp->ConsumeIntegral<int32_t>());

// Values used by findThumbnailInfo
newMeta->setInt32(kKeyThumbnailWidth, fdp->ConsumeIntegral<int32_t>());
newMeta->setInt32(kKeyThumbnailHeight, fdp->ConsumeIntegral<int32_t>());
size_t thumbnail_size =
fdp->ConsumeIntegralInRange<size_t>(0, MAX_METADATA_BUF_SIZE);
std::vector<uint8_t> thumb_bytes =
fdp->ConsumeBytes<uint8_t>(thumbnail_size);
newMeta->setData(kKeyThumbnailHVCC,
fdp->ConsumeIntegral<int32_t>(),
thumb_bytes.empty() ? nullptr : thumb_bytes.data(),
thumb_bytes.size());

// Values used by findGridInfo
newMeta->setInt32(kKeyTileWidth, fdp->ConsumeIntegral<int32_t>());
newMeta->setInt32(kKeyTileHeight, fdp->ConsumeIntegral<int32_t>());
newMeta->setInt32(kKeyGridRows, fdp->ConsumeIntegral<int32_t>());
newMeta->setInt32(kKeyGridCols, fdp->ConsumeIntegral<int32_t>());

// A few functions perform a CHECK() that height/width are set
newMeta->setInt32(kKeyHeight, fdp->ConsumeIntegral<int32_t>());
newMeta->setInt32(kKeyWidth, fdp->ConsumeIntegral<int32_t>());

return newMeta;
}
Expand Down
Loading

0 comments on commit 5b7ad60

Please sign in to comment.