• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "playerseek_fuzzer.h"
17 #include <iostream>
18 #include "string_ex.h"
19 #include "media_errors.h"
20 #include "directory_ex.h"
21 #include "ui/rs_surface_node.h"
22 #include "window_option.h"
23 
24 using namespace std;
25 using namespace OHOS;
26 using namespace OHOS::Media;
27 
PlayerSeekFuzzer()28 PlayerSeekFuzzer::PlayerSeekFuzzer()
29 {
30 }
31 
~PlayerSeekFuzzer()32 PlayerSeekFuzzer::~PlayerSeekFuzzer()
33 {
34 }
35 
36 namespace OHOS {
37 namespace Media {
FuzzSeek(uint8_t * data,size_t size)38 bool PlayerSeekFuzzer::FuzzSeek(uint8_t* data, size_t size)
39 {
40     player_ = OHOS::Media::PlayerFactory::CreatePlayer();
41     if (player_ == nullptr) {
42         cout << "player_ is null" << endl;
43         return false;
44     }
45     std::shared_ptr<TestPlayerCallback> cb = std::make_shared<TestPlayerCallback>();
46     int32_t ret = player_->SetPlayerCallback(cb);
47     if (ret != 0) {
48         cout << "SetPlayerCallback fail" << endl;
49     }
50     const string path = "/data/test/media/H264_AAC.mp4";
51     SetFdSource(path);
52     sptr<Surface> producerSurface = nullptr;
53     producerSurface = GetVideoSurface();
54     player_->SetVideoSurface(producerSurface);
55     player_->PrepareAsync();
56     sleep(1);
57     player_->Play();
58     if (size >= sizeof(int32_t)) {
59         int32_t data_ = *reinterpret_cast<int32_t *>(data);
60         player_->Seek(data_, SEEK_NEXT_SYNC);
61         sleep(1);
62     }
63     player_->Release();
64     return true;
65 }
66 }
67 
FuzzPlayerSeek(uint8_t * data,size_t size)68 bool FuzzPlayerSeek(uint8_t* data, size_t size)
69 {
70     auto player = std::make_unique<PlayerSeekFuzzer>();
71     if (player == nullptr) {
72         return true;
73     }
74     return player->FuzzSeek(data, size);
75 }
76 }
77 
78 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(uint8_t * data,size_t size)79 extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size)
80 {
81     /* Run your code on data */
82     FuzzPlayerSeek(data, size);
83     return 0;
84 }
85