Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at: |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * |
| 16 | */ |
| 17 | |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 18 | #include <MediaExtractorService.h> |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 19 | #include <MediaPlayerService.h> |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 20 | #include <android/gui/BnSurfaceComposerClient.h> |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 21 | #include <camera/Camera.h> |
| 22 | #include <datasource/FileSource.h> |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 23 | #include <fuzzbinder/random_binder.h> |
| 24 | #include <gmock/gmock.h> |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 25 | #include <gui/Surface.h> |
| 26 | #include <gui/SurfaceComposerClient.h> |
| 27 | #include <media/IMediaCodecList.h> |
| 28 | #include <media/IMediaHTTPService.h> |
| 29 | #include <media/IMediaPlayer.h> |
| 30 | #include <media/IMediaRecorder.h> |
| 31 | #include <media/IRemoteDisplay.h> |
| 32 | #include <media/IRemoteDisplayClient.h> |
Devendra Singhi | 0ecebb0 | 2022-04-13 09:55:57 +0530 | [diff] [blame] | 33 | #include <media/MediaHTTPConnection.h> |
| 34 | #include <media/MediaHTTPService.h> |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 35 | #include <media/stagefright/RemoteDataSource.h> |
| 36 | #include <media/stagefright/foundation/base64.h> |
| 37 | #include <thread> |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 38 | #include "android-base/stringprintf.h" |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 39 | #include "fuzzer/FuzzedDataProvider.h" |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 40 | using namespace std; |
| 41 | using namespace android; |
| 42 | |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 43 | constexpr int32_t kUuidSize = 16; |
| 44 | constexpr int32_t kMinSize = 0; |
| 45 | constexpr int32_t kMaxSize = 100; |
| 46 | constexpr int32_t kFourCCVal = android::FOURCC('m', 't', 'r', 'X'); |
| 47 | constexpr int32_t kFlagVal = |
| 48 | ISurfaceComposerClient::eCursorWindow | ISurfaceComposerClient::eOpaque; |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 49 | |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 50 | const char dumpFile[] = "OutputDumpFile"; |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 51 | |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 52 | enum DataSourceType { HTTP, FD, STREAM, FILETYPE, SOCKET, kMaxValue = SOCKET }; |
| 53 | |
| 54 | constexpr PixelFormat kPixelFormat[] = { |
| 55 | PIXEL_FORMAT_UNKNOWN, PIXEL_FORMAT_NONE, PIXEL_FORMAT_CUSTOM, |
| 56 | PIXEL_FORMAT_TRANSLUCENT, PIXEL_FORMAT_TRANSPARENT, PIXEL_FORMAT_OPAQUE, |
| 57 | PIXEL_FORMAT_RGBA_8888, PIXEL_FORMAT_RGBX_8888, PIXEL_FORMAT_RGB_888, |
| 58 | PIXEL_FORMAT_RGB_565, PIXEL_FORMAT_BGRA_8888, PIXEL_FORMAT_RGBA_5551, |
| 59 | PIXEL_FORMAT_RGBA_4444, PIXEL_FORMAT_RGBA_FP16, PIXEL_FORMAT_RGBA_1010102, |
| 60 | PIXEL_FORMAT_R_8, PIXEL_FORMAT_R_16_UINT, PIXEL_FORMAT_RG_1616_UINT, |
| 61 | PIXEL_FORMAT_RGBA_10101010, |
| 62 | }; |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 63 | |
| 64 | constexpr media_parameter_keys kMediaParamKeys[] = { |
| 65 | KEY_PARAMETER_CACHE_STAT_COLLECT_FREQ_MS, KEY_PARAMETER_AUDIO_CHANNEL_COUNT, |
| 66 | KEY_PARAMETER_PLAYBACK_RATE_PERMILLE, KEY_PARAMETER_AUDIO_ATTRIBUTES, |
| 67 | KEY_PARAMETER_RTP_ATTRIBUTES}; |
| 68 | |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 69 | constexpr media_event_type kMediaEventTypes[] = {MEDIA_NOP, |
| 70 | MEDIA_PREPARED, |
| 71 | MEDIA_PLAYBACK_COMPLETE, |
| 72 | MEDIA_BUFFERING_UPDATE, |
| 73 | MEDIA_SEEK_COMPLETE, |
| 74 | MEDIA_SET_VIDEO_SIZE, |
| 75 | MEDIA_STARTED, |
| 76 | MEDIA_PAUSED, |
| 77 | MEDIA_STOPPED, |
| 78 | MEDIA_SKIPPED, |
| 79 | MEDIA_NOTIFY_TIME, |
| 80 | MEDIA_TIMED_TEXT, |
| 81 | MEDIA_ERROR, |
| 82 | MEDIA_INFO, |
| 83 | MEDIA_SUBTITLE_DATA, |
| 84 | MEDIA_META_DATA, |
| 85 | MEDIA_DRM_INFO, |
| 86 | MEDIA_TIME_DISCONTINUITY, |
| 87 | MEDIA_IMS_RX_NOTICE, |
| 88 | MEDIA_AUDIO_ROUTING_CHANGED}; |
| 89 | |
| 90 | constexpr media_info_type kMediaInfoTypes[] = { |
| 91 | MEDIA_INFO_UNKNOWN, MEDIA_INFO_STARTED_AS_NEXT, |
| 92 | MEDIA_INFO_RENDERING_START, MEDIA_INFO_VIDEO_TRACK_LAGGING, |
| 93 | MEDIA_INFO_BUFFERING_START, MEDIA_INFO_BUFFERING_END, |
| 94 | MEDIA_INFO_NETWORK_BANDWIDTH, MEDIA_INFO_BAD_INTERLEAVING, |
| 95 | MEDIA_INFO_NOT_SEEKABLE, MEDIA_INFO_METADATA_UPDATE, |
| 96 | MEDIA_INFO_PLAY_AUDIO_ERROR, MEDIA_INFO_PLAY_VIDEO_ERROR, |
| 97 | MEDIA_INFO_TIMED_TEXT_ERROR}; |
| 98 | |
| 99 | const char *kUrlPrefix[] = {"data:", "http://", "https://", "rtsp://", "content://", "test://"}; |
| 100 | |
| 101 | struct TestStreamSource : public IStreamSource { |
| 102 | void setListener(const sp<IStreamListener> & /*listener*/) override{}; |
| 103 | void setBuffers(const Vector<sp<IMemory>> & /*buffers*/) override{}; |
| 104 | void onBufferAvailable(size_t /*index*/) override{}; |
| 105 | IBinder *onAsBinder() { return nullptr; }; |
| 106 | }; |
| 107 | |
Devendra Singhi | 0ecebb0 | 2022-04-13 09:55:57 +0530 | [diff] [blame] | 108 | struct TestMediaHTTPConnection : public MediaHTTPConnection { |
| 109 | public: |
| 110 | TestMediaHTTPConnection() {} |
| 111 | virtual ~TestMediaHTTPConnection() {} |
| 112 | |
| 113 | virtual bool connect(const char* /*uri*/, const KeyedVector<String8, String8>* /*headers*/) { |
| 114 | return true; |
| 115 | } |
| 116 | |
| 117 | virtual void disconnect() { return; } |
| 118 | |
| 119 | virtual ssize_t readAt(off64_t /*offset*/, void* /*data*/, size_t size) { return size; } |
| 120 | |
| 121 | virtual off64_t getSize() { return 0; } |
| 122 | virtual status_t getMIMEType(String8* /*mimeType*/) { return NO_ERROR; } |
| 123 | virtual status_t getUri(String8* /*uri*/) { return NO_ERROR; } |
| 124 | |
| 125 | private: |
| 126 | DISALLOW_EVIL_CONSTRUCTORS(TestMediaHTTPConnection); |
| 127 | }; |
| 128 | |
| 129 | struct TestMediaHTTPService : public BnInterface<IMediaHTTPService> { |
| 130 | public: |
| 131 | TestMediaHTTPService() {} |
| 132 | ~TestMediaHTTPService(){}; |
| 133 | |
| 134 | virtual sp<MediaHTTPConnection> makeHTTPConnection() { |
| 135 | mMediaHTTPConnection = sp<TestMediaHTTPConnection>::make(); |
| 136 | return mMediaHTTPConnection; |
| 137 | } |
| 138 | |
| 139 | private: |
| 140 | sp<TestMediaHTTPConnection> mMediaHTTPConnection = nullptr; |
| 141 | DISALLOW_EVIL_CONSTRUCTORS(TestMediaHTTPService); |
| 142 | }; |
| 143 | |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 144 | class FakeBnSurfaceComposerClient : public gui::BnSurfaceComposerClient { |
| 145 | public: |
| 146 | MOCK_METHOD(binder::Status, createSurface, |
| 147 | (const std::string& name, int32_t flags, const sp<IBinder>& parent, |
| 148 | const gui::LayerMetadata& metadata, gui::CreateSurfaceResult* outResult), |
| 149 | (override)); |
| 150 | |
| 151 | MOCK_METHOD(binder::Status, clearLayerFrameStats, (const sp<IBinder>& handle), (override)); |
| 152 | |
| 153 | MOCK_METHOD(binder::Status, getLayerFrameStats, |
| 154 | (const sp<IBinder>& handle, gui::FrameStats* outStats), (override)); |
| 155 | |
| 156 | MOCK_METHOD(binder::Status, mirrorSurface, |
| 157 | (const sp<IBinder>& mirrorFromHandle, gui::CreateSurfaceResult* outResult), |
| 158 | (override)); |
| 159 | |
| 160 | MOCK_METHOD(binder::Status, mirrorDisplay, |
| 161 | (int64_t displayId, gui::CreateSurfaceResult* outResult), (override)); |
| 162 | |
| 163 | MOCK_METHOD(binder::Status, getSchedulingPolicy, (gui::SchedulingPolicy*), (override)); |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 164 | }; |
| 165 | |
| 166 | class MediaPlayerServiceFuzzer { |
| 167 | public: |
| 168 | MediaPlayerServiceFuzzer(const uint8_t *data, size_t size) |
| 169 | : mFdp(data, size), mDataSourceFd(memfd_create("InputFile", MFD_ALLOW_SEALING)){}; |
| 170 | ~MediaPlayerServiceFuzzer() { close(mDataSourceFd); }; |
| 171 | void process(const uint8_t *data, size_t size); |
| 172 | |
| 173 | private: |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 174 | FuzzedDataProvider mFdp; |
| 175 | const int32_t mDataSourceFd; |
| 176 | sp<IMediaPlayer> mMediaPlayer = nullptr; |
| 177 | sp<IMediaPlayerClient> mMediaPlayerClient = nullptr; |
| 178 | void invokeMediaPlayer(); |
| 179 | sp<SurfaceControl> makeSurfaceControl(); |
| 180 | bool setDataSource(const uint8_t* data, size_t size); |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 181 | }; |
| 182 | |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 183 | sp<SurfaceControl> MediaPlayerServiceFuzzer::makeSurfaceControl() { |
| 184 | sp<IBinder> handle = getRandomBinder(&mFdp); |
| 185 | const sp<FakeBnSurfaceComposerClient> testClient(new FakeBnSurfaceComposerClient()); |
| 186 | sp<SurfaceComposerClient> client = new SurfaceComposerClient(testClient); |
| 187 | uint32_t width = mFdp.ConsumeIntegral<uint32_t>(); |
| 188 | uint32_t height = mFdp.ConsumeIntegral<uint32_t>(); |
| 189 | uint32_t transformHint = mFdp.ConsumeIntegral<uint32_t>(); |
| 190 | uint32_t flags = mFdp.ConsumeBool() ? kFlagVal : mFdp.ConsumeIntegral<uint32_t>(); |
| 191 | int32_t format = mFdp.ConsumeBool() ? mFdp.ConsumeIntegral<uint32_t>() |
| 192 | : mFdp.PickValueInArray(kPixelFormat); |
| 193 | int32_t layerId = mFdp.ConsumeIntegral<int32_t>(); |
| 194 | std::string layerName = android::base::StringPrintf("#%d", layerId); |
| 195 | return new SurfaceControl(client, handle, layerId, layerName, width, height, format, |
| 196 | transformHint, flags); |
| 197 | } |
| 198 | |
| 199 | bool MediaPlayerServiceFuzzer::setDataSource(const uint8_t* data, size_t size) { |
| 200 | status_t status = UNKNOWN_ERROR; |
| 201 | switch (mFdp.ConsumeEnum<DataSourceType>()) { |
| 202 | case HTTP: { |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 203 | KeyedVector<String8, String8> headers; |
| 204 | headers.add(String8(mFdp.ConsumeRandomLengthString().c_str()), |
| 205 | String8(mFdp.ConsumeRandomLengthString().c_str())); |
| 206 | |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 207 | uint32_t dataBlobSize = mFdp.ConsumeIntegralInRange<uint16_t>(kMinSize, size); |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 208 | vector<uint8_t> uriSuffix = mFdp.ConsumeBytes<uint8_t>(dataBlobSize); |
| 209 | |
| 210 | string uri(mFdp.PickValueInArray(kUrlPrefix)); |
| 211 | uri += ";base64,"; |
| 212 | AString out; |
| 213 | encodeBase64(uriSuffix.data(), uriSuffix.size(), &out); |
| 214 | uri += out.c_str(); |
Devendra Singhi | 0ecebb0 | 2022-04-13 09:55:57 +0530 | [diff] [blame] | 215 | sp<TestMediaHTTPService> testService = sp<TestMediaHTTPService>::make(); |
| 216 | status = |
| 217 | mMediaPlayer->setDataSource(testService /*httpService*/, uri.c_str(), &headers); |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 218 | break; |
| 219 | } |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 220 | case FD: { |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 221 | write(mDataSourceFd, data, size); |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 222 | status = mMediaPlayer->setDataSource(mDataSourceFd, 0, size); |
| 223 | break; |
| 224 | } |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 225 | case STREAM: { |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 226 | sp<IStreamSource> streamSource = sp<TestStreamSource>::make(); |
| 227 | status = mMediaPlayer->setDataSource(streamSource); |
| 228 | break; |
| 229 | } |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 230 | case FILETYPE: { |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 231 | write(mDataSourceFd, data, size); |
| 232 | |
| 233 | sp<DataSource> dataSource = new FileSource(dup(mDataSourceFd), 0, size); |
| 234 | sp<IDataSource> iDataSource = RemoteDataSource::wrap(dataSource); |
| 235 | if (!iDataSource) { |
| 236 | return false; |
| 237 | } |
| 238 | status = mMediaPlayer->setDataSource(iDataSource); |
| 239 | break; |
| 240 | } |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 241 | case SOCKET: { |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 242 | String8 rtpParams = String8(mFdp.ConsumeRandomLengthString().c_str()); |
| 243 | struct sockaddr_in endpoint; |
| 244 | endpoint.sin_family = mFdp.ConsumeIntegral<unsigned short>(); |
| 245 | endpoint.sin_port = mFdp.ConsumeIntegral<uint16_t>(); |
| 246 | mMediaPlayer->setRetransmitEndpoint(&endpoint); |
| 247 | status = mMediaPlayer->setDataSource(rtpParams); |
| 248 | break; |
| 249 | } |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 250 | } |
| 251 | if (status != OK) { |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 252 | return false; |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 253 | } |
| 254 | return true; |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | void MediaPlayerServiceFuzzer::invokeMediaPlayer() { |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 258 | Parcel request, reply; |
| 259 | while (mFdp.remaining_bytes()) { |
| 260 | auto invokeMediaPlayerApi = mFdp.PickValueInArray<const std::function<void()>>({ |
| 261 | [&]() { |
| 262 | sp<SurfaceControl> surfaceControl = makeSurfaceControl(); |
| 263 | if (surfaceControl) { |
| 264 | sp<Surface> surface = surfaceControl->getSurface(); |
| 265 | mMediaPlayer->setVideoSurfaceTexture(surface->getIGraphicBufferProducer()); |
| 266 | } |
| 267 | }, |
| 268 | [&]() { |
| 269 | BufferingSettings buffering; |
| 270 | buffering.mInitialMarkMs = mFdp.ConsumeIntegral<int32_t>(); |
| 271 | buffering.mResumePlaybackMarkMs = mFdp.ConsumeIntegral<int32_t>(); |
| 272 | mMediaPlayer->setBufferingSettings(buffering); |
| 273 | }, |
| 274 | [&]() { |
| 275 | BufferingSettings buffering; |
| 276 | mMediaPlayer->getBufferingSettings(&buffering); |
| 277 | }, |
| 278 | [&]() { |
| 279 | mMediaPlayer->prepareAsync(); |
| 280 | this_thread::sleep_for(chrono::milliseconds(100)); // Time to post message |
| 281 | }, |
| 282 | [&]() { |
| 283 | mMediaPlayer->start(); |
| 284 | this_thread::sleep_for(chrono::milliseconds(100)); // Time to post message |
| 285 | }, |
| 286 | [&]() { |
| 287 | mMediaPlayer->pause(); |
| 288 | this_thread::sleep_for(chrono::milliseconds(100)); // Time to post message |
| 289 | }, |
| 290 | [&]() { mMediaPlayer->stop(); }, |
| 291 | [&]() { |
| 292 | bool state; |
| 293 | mMediaPlayer->isPlaying(&state); |
| 294 | }, |
| 295 | [&]() { |
| 296 | AudioPlaybackRate rate; |
| 297 | rate.mSpeed = mFdp.ConsumeFloatingPoint<float>(); |
| 298 | rate.mPitch = mFdp.ConsumeFloatingPoint<float>(); |
| 299 | rate.mStretchMode = mFdp.ConsumeBool() ? AUDIO_TIMESTRETCH_STRETCH_DEFAULT |
| 300 | : AUDIO_TIMESTRETCH_STRETCH_VOICE; |
| 301 | rate.mFallbackMode = |
| 302 | (audio_timestretch_fallback_mode_t)mFdp.ConsumeIntegralInRange<int32_t>( |
| 303 | AUDIO_TIMESTRETCH_FALLBACK_CUT_REPEAT, |
| 304 | AUDIO_TIMESTRETCH_FALLBACK_FAIL); |
| 305 | mMediaPlayer->setPlaybackSettings(rate); |
| 306 | mMediaPlayer->getPlaybackSettings(&rate); |
| 307 | }, |
| 308 | [&]() { |
| 309 | AVSyncSettings* avSyncSettings = new AVSyncSettings(); |
| 310 | float videoFpsHint = mFdp.ConsumeFloatingPoint<float>(); |
| 311 | mMediaPlayer->setSyncSettings(*avSyncSettings, videoFpsHint); |
| 312 | delete avSyncSettings; |
| 313 | }, |
| 314 | [&]() { |
| 315 | AVSyncSettings* avSyncSettings = new AVSyncSettings(); |
| 316 | float videoFpsHint = 0; |
| 317 | mMediaPlayer->getSyncSettings(avSyncSettings, &videoFpsHint); |
| 318 | delete avSyncSettings; |
| 319 | }, |
| 320 | [&]() { mMediaPlayer->seekTo(mFdp.ConsumeIntegral<int32_t>()); }, |
| 321 | [&]() { |
| 322 | int32_t msec; |
| 323 | mMediaPlayer->getCurrentPosition(&msec); |
| 324 | mMediaPlayer->getDuration(&msec); |
| 325 | }, |
| 326 | [&]() { mMediaPlayer->reset(); }, |
| 327 | [&]() { mMediaPlayer->notifyAt(mFdp.ConsumeIntegral<uint64_t>()); }, |
| 328 | [&]() { |
| 329 | mMediaPlayer->setAudioStreamType( |
| 330 | (audio_stream_type_t)mFdp.ConsumeIntegralInRange<int32_t>( |
| 331 | AUDIO_STREAM_VOICE_CALL, AUDIO_STREAM_CALL_ASSISTANT)); |
| 332 | }, |
| 333 | [&]() { mMediaPlayer->setLooping(mFdp.ConsumeIntegral<int32_t>()); }, |
| 334 | [&]() { |
| 335 | mMediaPlayer->setVolume(mFdp.ConsumeFloatingPoint<float>() /* left */, |
| 336 | mFdp.ConsumeFloatingPoint<float>() /* right */); |
| 337 | }, |
| 338 | [&]() { |
| 339 | request.writeInt32(mFdp.ConsumeIntegral<int32_t>()); |
| 340 | request.setDataPosition(0); |
| 341 | mMediaPlayer->invoke(request, &reply); |
| 342 | }, |
| 343 | [&]() { |
| 344 | Parcel filter; |
| 345 | filter.writeInt32(mFdp.ConsumeIntegral<int32_t>()); |
| 346 | filter.setDataPosition(0); |
| 347 | mMediaPlayer->setMetadataFilter(filter); |
| 348 | }, |
| 349 | [&]() { |
| 350 | mMediaPlayer->getMetadata(mFdp.ConsumeBool() /* updateOnly */, |
| 351 | mFdp.ConsumeBool() /* applyFilter */, &reply); |
| 352 | }, |
| 353 | [&]() { mMediaPlayer->setAuxEffectSendLevel(mFdp.ConsumeFloatingPoint<float>()); }, |
| 354 | [&]() { mMediaPlayer->attachAuxEffect(mFdp.ConsumeIntegral<int32_t>()); }, |
| 355 | [&]() { |
| 356 | int32_t key = mFdp.PickValueInArray(kMediaParamKeys); |
| 357 | request.writeInt32(mFdp.ConsumeIntegral<int32_t>()); |
| 358 | request.setDataPosition(0); |
| 359 | mMediaPlayer->setParameter(key, request); |
| 360 | key = mFdp.PickValueInArray(kMediaParamKeys); |
| 361 | mMediaPlayer->getParameter(key, &reply); |
| 362 | }, |
| 363 | [&]() { |
| 364 | int32_t key = |
| 365 | mFdp.ConsumeBool() ? kFourCCVal : mFdp.ConsumeIntegral<uint32_t>(); |
| 366 | mMediaPlayer->getParameter(key, &reply); |
| 367 | }, |
| 368 | [&]() { |
| 369 | struct sockaddr_in endpoint; |
| 370 | mMediaPlayer->getRetransmitEndpoint(&endpoint); |
| 371 | }, |
| 372 | [&]() { |
| 373 | AttributionSourceState attributionSource; |
| 374 | attributionSource.packageName = mFdp.ConsumeRandomLengthString().c_str(); |
| 375 | attributionSource.token = sp<BBinder>::make(); |
| 376 | const sp<IMediaPlayerService> mpService( |
| 377 | IMediaDeathNotifier::getMediaPlayerService()); |
| 378 | audio_session_t audioSessionId = |
| 379 | (audio_session_t)mFdp.ConsumeIntegralInRange<int32_t>( |
| 380 | AUDIO_SESSION_DEVICE, AUDIO_SESSION_OUTPUT_MIX); |
| 381 | sp<IMediaPlayer> mNextMediaPlayer = mpService->create( |
| 382 | mMediaPlayerClient, audioSessionId, attributionSource); |
| 383 | mMediaPlayer->setNextPlayer(mNextMediaPlayer); |
| 384 | }, |
| 385 | [&]() { |
| 386 | const sp<media::VolumeShaper::Configuration> configuration = |
| 387 | sp<media::VolumeShaper::Configuration>::make(); |
| 388 | const sp<media::VolumeShaper::Operation> operation = |
| 389 | sp<media::VolumeShaper::Operation>::make(); |
| 390 | mMediaPlayer->applyVolumeShaper(configuration, operation); |
| 391 | }, |
| 392 | [&]() { mMediaPlayer->getVolumeShaperState(mFdp.ConsumeIntegral<int32_t>()); }, |
| 393 | [&]() { |
| 394 | uint8_t uuid[kUuidSize]; |
| 395 | for (int32_t index = 0; index < kUuidSize; ++index) { |
| 396 | uuid[index] = mFdp.ConsumeIntegral<uint8_t>(); |
| 397 | } |
| 398 | Vector<uint8_t> drmSessionId; |
| 399 | int32_t length = mFdp.ConsumeIntegralInRange<uint32_t>(kMinSize, kMaxSize); |
| 400 | while (length--) { |
| 401 | drmSessionId.push_back(mFdp.ConsumeIntegral<uint8_t>()); |
| 402 | } |
| 403 | mMediaPlayer->prepareDrm(uuid, drmSessionId); |
| 404 | }, |
| 405 | [&]() { mMediaPlayer->releaseDrm(); }, |
| 406 | [&]() { |
| 407 | audio_port_handle_t deviceId = mFdp.ConsumeIntegral<int32_t>(); |
| 408 | mMediaPlayer->setOutputDevice(deviceId); |
| 409 | }, |
| 410 | [&]() { |
| 411 | audio_port_handle_t deviceId; |
| 412 | mMediaPlayer->getRoutedDeviceId(&deviceId); |
| 413 | }, |
| 414 | [&]() { mMediaPlayer->enableAudioDeviceCallback(mFdp.ConsumeBool()); }, |
| 415 | [&]() { |
| 416 | sp<MediaPlayer> mediaPlayer = (MediaPlayer*)mMediaPlayer.get(); |
| 417 | Parcel obj; |
| 418 | obj.writeInt32(mFdp.ConsumeIntegral<int32_t>()); |
| 419 | obj.setDataPosition(0); |
| 420 | mediaPlayer->notify(mFdp.PickValueInArray(kMediaEventTypes) /* msg */, |
| 421 | mFdp.PickValueInArray(kMediaInfoTypes) /* ext1 */, |
| 422 | mFdp.ConsumeIntegral<int32_t>() /* ext2 */, &obj); |
| 423 | }, |
| 424 | [&]() { |
| 425 | sp<MediaPlayer> mediaPlayer = (MediaPlayer*)mMediaPlayer.get(); |
| 426 | int32_t mediaPlayerDumpFd = memfd_create(dumpFile, MFD_ALLOW_SEALING); |
| 427 | Vector<String16> args; |
| 428 | args.push_back(String16(mFdp.ConsumeRandomLengthString().c_str())); |
| 429 | mediaPlayer->dump(mediaPlayerDumpFd, args); |
| 430 | close(mediaPlayerDumpFd); |
| 431 | }, |
| 432 | [&]() { mMediaPlayer->disconnect(); }, |
| 433 | }); |
| 434 | invokeMediaPlayerApi(); |
| 435 | } |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 436 | } |
| 437 | |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 438 | void MediaPlayerServiceFuzzer::process(const uint8_t* data, size_t size) { |
| 439 | const sp<IMediaPlayerService> mpService(IMediaDeathNotifier::getMediaPlayerService()); |
| 440 | if (!mpService) { |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 441 | return; |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 442 | } |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 443 | |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 444 | sp<IMediaCodecList> mediaCodecList = mpService->getCodecList(); |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 445 | |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 446 | sp<IRemoteDisplayClient> remoteDisplayClient; |
| 447 | sp<IRemoteDisplay> remoteDisplay = mpService->listenForRemoteDisplay( |
| 448 | String16(mFdp.ConsumeRandomLengthString().c_str()) /*opPackageName*/, |
| 449 | remoteDisplayClient, String8(mFdp.ConsumeRandomLengthString().c_str()) /*iface*/); |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 450 | |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 451 | mpService->addBatteryData(mFdp.ConsumeIntegral<uint32_t>()); |
| 452 | Parcel reply; |
| 453 | mpService->pullBatteryData(&reply); |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 454 | |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 455 | sp<MediaPlayerService> mediaPlayerService = (MediaPlayerService*)mpService.get(); |
| 456 | AttributionSourceState attributionSource; |
| 457 | attributionSource.packageName = mFdp.ConsumeRandomLengthString().c_str(); |
| 458 | attributionSource.token = sp<BBinder>::make(); |
| 459 | mMediaPlayer = |
| 460 | mediaPlayerService->create(mMediaPlayerClient, |
| 461 | (audio_session_t)mFdp.ConsumeIntegralInRange<int32_t>( |
| 462 | AUDIO_SESSION_DEVICE, AUDIO_SESSION_OUTPUT_MIX), |
| 463 | attributionSource); |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 464 | |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 465 | int32_t mediaPlayerServiceDumpFd = memfd_create(dumpFile, MFD_ALLOW_SEALING); |
| 466 | Vector<String16> args; |
| 467 | args.push_back(String16(mFdp.ConsumeRandomLengthString().c_str())); |
| 468 | mediaPlayerService->dump(mediaPlayerServiceDumpFd, args); |
| 469 | close(mediaPlayerServiceDumpFd); |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 470 | |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 471 | if (!mMediaPlayer) { |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 472 | return; |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 473 | } |
| 474 | if (setDataSource(data, size)) { |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 475 | invokeMediaPlayer(); |
Onkar Shinde | c9f1180 | 2023-11-30 11:46:48 +0530 | [diff] [blame^] | 476 | } |
| 477 | } |
| 478 | |
| 479 | extern "C" int LLVMFuzzerInitialize(int* /* argc */, char*** /* argv */) { |
| 480 | MediaPlayerService::instantiate(); |
| 481 | MediaExtractorService::instantiate(); |
| 482 | return 0; |
Chethan Kumar R E | bb0cd95 | 2021-08-02 15:02:52 +0530 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
| 486 | MediaPlayerServiceFuzzer mpsFuzzer(data, size); |
| 487 | ProcessState::self()->startThreadPool(); |
| 488 | mpsFuzzer.process(data, size); |
| 489 | return 0; |
| 490 | }; |