/* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "bufferutils_fuzzer.h" #include #include #include "data_generate.h" #include "surface_buffer.h" #include "surface_buffer_impl.h" #include "buffer_utils.h" #include "sandbox_utils.h" #include using namespace g_fuzzCommon; namespace OHOS { bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { if (data == nullptr) { return false; } int fd = GetData(); BufferRequestConfig rqConfig = GetData(); BufferFlushConfigWithDamages flConfig = { .damages = { GetData() }, .timestamp = GetData(), }; uint32_t seqNum = GetData(); uint32_t sequence = GetData(); BufferVerifyAllocInfo vaInfo = GetData(); GraphicHDRMetaData metaData = GetData(); uint8_t metaData2 = GetData(); uint32_t reserveInts = GetData() % 0x100000; // no more than 0x100000 MessageParcel parcel; sptr buffer = new SurfaceBufferImpl(seqNum); WriteFileDescriptor(parcel, fd); ReadFileDescriptor(parcel, fd); WriteRequestConfig(parcel, rqConfig); ReadRequestConfig(parcel, rqConfig); WriteFlushConfig(parcel, flConfig); ReadFlushConfig(parcel, flConfig); WriteSurfaceBufferImpl(parcel, sequence, buffer); ReadSurfaceBufferImpl(parcel, sequence, buffer); std::vector infos = {vaInfo}; WriteVerifyAllocInfo(parcel, infos); ReadVerifyAllocInfo(parcel, infos); std::vector metaDatas = {metaData}; WriteHDRMetaData(parcel, metaDatas); ReadHDRMetaData(parcel, metaDatas); std::vector metaDatas2 = {metaData2}; WriteHDRMetaDataSet(parcel, metaDatas2); ReadHDRMetaDataSet(parcel, metaDatas2); GraphicExtDataHandle *handle = AllocExtDataHandle(reserveInts); WriteExtDataHandle(parcel, handle); sptr tunnelHandle = nullptr; ReadExtDataHandle(parcel, tunnelHandle); sptr tunnelHandle2 = new SurfaceTunnelHandle(); ReadExtDataHandle(parcel, tunnelHandle); tunnelHandle2->SetHandle(handle); tunnelHandle2->GetHandle(); tunnelHandle2->Different(tunnelHandle); FreeExtDataHandle(handle); DumpToFileAsync(GetRealPid(), "test", buffer); return true; } } // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ g_data = data; g_size = size; g_pos = 0; OHOS::DoSomethingInterestingWithMyAPI(data, size); return 0; }