1
2 /*
3 * Copyright (C) 2020 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #pragma once
19
20 #include <media/stagefright/MetaData.h>
21 #include "MediaMimeTypes.h"
22
23 #define MAX_METADATA_BUF_SIZE 512
24
25 namespace android {
26
27 std::vector<std::shared_ptr<char>> generated_mime_types;
28
generateMetaData(FuzzedDataProvider * fdp)29 sp<MetaData> generateMetaData(FuzzedDataProvider *fdp) {
30 sp<MetaData> newMeta = new MetaData();
31
32 // random MIME Type
33 const char *mime_type;
34 size_t index = fdp->ConsumeIntegralInRange<size_t>(0, kMimeTypes.size());
35 // Let there be a chance of a true random string
36 if (index == kMimeTypes.size()) {
37 std::string mime_str = fdp->ConsumeRandomLengthString(64);
38 std::shared_ptr<char> mime_cstr(new char[mime_str.length()+1]);
39 generated_mime_types.push_back(mime_cstr);
40 strncpy(mime_cstr.get(), mime_str.c_str(), mime_str.length()+1);
41 mime_type = mime_cstr.get();
42 } else {
43 mime_type = kMimeTypes[index];
44 }
45 newMeta->setCString(kKeyMIMEType, mime_type);
46
47 // Thumbnail time
48 newMeta->setInt64(kKeyThumbnailTime, fdp->ConsumeIntegral<int64_t>());
49
50 // Values used by allocVideoFrame
51 newMeta->setInt32(kKeyRotation, fdp->ConsumeIntegral<int32_t>());
52 size_t profile_size =
53 fdp->ConsumeIntegralInRange<size_t>(0, MAX_METADATA_BUF_SIZE);
54 std::vector<uint8_t> profile_bytes =
55 fdp->ConsumeBytes<uint8_t>(profile_size);
56 newMeta->setData(kKeyIccProfile,
57 fdp->ConsumeIntegral<int32_t>(),
58 profile_bytes.empty() ? nullptr : profile_bytes.data(),
59 profile_bytes.size());
60 newMeta->setInt32(kKeySARWidth, fdp->ConsumeIntegral<int32_t>());
61 newMeta->setInt32(kKeySARHeight, fdp->ConsumeIntegral<int32_t>());
62 newMeta->setInt32(kKeyDisplayWidth, fdp->ConsumeIntegral<int32_t>());
63 newMeta->setInt32(kKeyDisplayHeight, fdp->ConsumeIntegral<int32_t>());
64
65 // Values used by findThumbnailInfo
66 newMeta->setInt32(kKeyThumbnailWidth, fdp->ConsumeIntegral<int32_t>());
67 newMeta->setInt32(kKeyThumbnailHeight, fdp->ConsumeIntegral<int32_t>());
68 size_t thumbnail_size =
69 fdp->ConsumeIntegralInRange<size_t>(0, MAX_METADATA_BUF_SIZE);
70 std::vector<uint8_t> thumb_bytes =
71 fdp->ConsumeBytes<uint8_t>(thumbnail_size);
72 newMeta->setData(kKeyThumbnailHVCC,
73 fdp->ConsumeIntegral<int32_t>(),
74 thumb_bytes.empty() ? nullptr : thumb_bytes.data(),
75 thumb_bytes.size());
76
77 // Values used by findGridInfo
78 newMeta->setInt32(kKeyTileWidth, fdp->ConsumeIntegral<int32_t>());
79 newMeta->setInt32(kKeyTileHeight, fdp->ConsumeIntegral<int32_t>());
80 newMeta->setInt32(kKeyGridRows, fdp->ConsumeIntegral<int32_t>());
81 newMeta->setInt32(kKeyGridCols, fdp->ConsumeIntegral<int32_t>());
82
83 // A few functions perform a CHECK() that height/width are set
84 newMeta->setInt32(kKeyHeight, fdp->ConsumeIntegral<int32_t>());
85 newMeta->setInt32(kKeyWidth, fdp->ConsumeIntegral<int32_t>());
86
87 return newMeta;
88 }
89
90 } // namespace android
91