1 /*
2 * Copyright (c) 2021-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 "common.h"
17 #include "offline_stream_operator.h"
18
19 namespace OHOS {
CameraOfflineStreamOperatorFuzzTest(const uint8_t * rawData,size_t size)20 bool CameraOfflineStreamOperatorFuzzTest(const uint8_t *rawData, size_t size)
21 {
22 if (rawData == nullptr) {
23 return false;
24 }
25 constexpr uint32_t sleepTime = 2;
26 uint32_t code = U32_AT(rawData);
27 rawData = rawData + OFFSET;
28 size = size - OFFSET;
29
30 MessageParcel data;
31 data.WriteInterfaceToken(IOfflineStreamOperator::GetDescriptor());
32 data.WriteBuffer(rawData, size);
33 data.RewindRead(0);
34 MessageParcel reply;
35 MessageOption option;
36
37 sptr<IOfflineStreamOperator> offlineStreamOperator = new OHOS::Camera::OfflineStreamOperator();
38 CHECK_IF_PTR_NULL_RETURN_VALUE(offlineStreamOperator, false);
39 sptr<OfflineStreamOperatorStub> IpcOfflineStream = new OfflineStreamOperatorStub(offlineStreamOperator);
40 CHECK_IF_PTR_NULL_RETURN_VALUE(IpcOfflineStream, false);
41
42 sleep(sleepTime); // sleep two second
43 IpcOfflineStream->OnRemoteRequest(code, data, reply, option);
44
45 return true;
46 }
47
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)48 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
49 {
50 if (size < OHOS::THRESHOLD) {
51 return 0;
52 }
53
54 CameraOfflineStreamOperatorFuzzTest(data, size);
55 return 0;
56 }
57 }
58