/* * Copyright (c) 2025 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 #include #include #include "camera_input.h" #include "camera_log.h" #include "camera_outputcapability_fuzzer.h" #include "camera_photo_proxy.h" #include "capture_input.h" #include "capture_output.h" #include "capture_scene_const.h" #include "input/camera_manager.h" #include "message_parcel.h" #include "refbase.h" #include "token_setproc.h" #include "nativetoken_kit.h" #include "accesstoken_kit.h" #include "securec.h" namespace OHOS { namespace CameraStandard { static constexpr int32_t MIN_SIZE_NUM = 4; std::shared_ptr CameraOutputCapabilityFuzzer::capabilityfuzz_{nullptr}; std::shared_ptr CameraOutputCapabilityFuzzer::profilefuzz_{nullptr}; std::shared_ptr CameraOutputCapabilityFuzzer::videoProfilefuzz_{nullptr}; void CameraOutputCapabilityFuzzer::CameraOutputCapabilityFuzzTest(FuzzedDataProvider& fdp) { int32_t value = fdp.ConsumeIntegralInRange(-2, 5); ProfileSizeRatio sizeRatio = static_cast(value); float unspecifiedValue = fdp.ConsumeFloatingPoint(); GetTargetRatio(sizeRatio, unspecifiedValue); value = fdp.ConsumeIntegral(); CameraFormat format = static_cast(value); Size profileSize; value = fdp.ConsumeIntegral(); profileSize.width = value; value = fdp.ConsumeIntegral(); profileSize.height = value; Fps fps; value = fdp.ConsumeIntegral(); fps.fixedFps = value; value = fdp.ConsumeIntegral(); fps.minFps = value; value = fdp.ConsumeIntegral(); fps.maxFps = value; std::vector abilityId; value = fdp.ConsumeIntegral(); abilityId.push_back(value); value = fdp.ConsumeIntegral(); abilityId.push_back(value); int32_t specId = fdp.ConsumeIntegral(); profilefuzz_ = std::make_shared(format, profileSize, fps, abilityId, specId); profilefuzz_->GetFps(); std::vector framerates; value = fdp.ConsumeIntegral(); framerates.push_back(value); value = fdp.ConsumeIntegral(); framerates.push_back(value); videoProfilefuzz_ = std::make_shared(format, profileSize, framerates); VideoProfile videoProfile1(format, profileSize, framerates); videoProfilefuzz_->IsContains(videoProfile1); format = static_cast(value); value = fdp.ConsumeIntegral(); profileSize.width = value; value = fdp.ConsumeIntegral(); profileSize.height = value; framerates.clear(); value = fdp.ConsumeIntegral(); framerates.push_back(value); value = fdp.ConsumeIntegral(); framerates.push_back(value); VideoProfile videoProfile2(format, profileSize, framerates); videoProfilefuzz_->IsContains(videoProfile2); capabilityfuzz_ = std::make_shared(); std::vector previewProfiles; value = fdp.ConsumeIntegral(); format = static_cast(value); Size profileSize1; value = fdp.ConsumeIntegral(); profileSize1.width = value; value = fdp.ConsumeIntegral(); profileSize1.height = value; Profile profile1(format, profileSize1); previewProfiles.push_back(profile1); capabilityfuzz_->previewProfiles_.push_back(profile1); capabilityfuzz_->IsMatchPreviewProfiles(previewProfiles); capabilityfuzz_->photoProfiles_.push_back(profile1); capabilityfuzz_->IsMatchPhotoProfiles(previewProfiles); capabilityfuzz_->videoProfiles_.push_back(videoProfile1); vectorvideoProfilevec = {videoProfile1}; capabilityfuzz_->IsMatchVideoProfiles(videoProfilevec); capabilityfuzz_->RemoveDuplicatesProfiles(); capabilityfuzz_->GetSupportedMetadataObjectType(); } void Test(uint8_t* data, size_t size) { auto cameraOutputCapability = std::make_unique(); if (cameraOutputCapability == nullptr) { MEDIA_INFO_LOG("cameraOutputCapability is null"); return; } FuzzedDataProvider fdp(data, size); if (fdp.remaining_bytes() < MIN_SIZE_NUM) { return; } cameraOutputCapability->CameraOutputCapabilityFuzzTest(fdp); } } // namespace CameraStandard } // namespace OHOS extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) { OHOS::CameraStandard::Test(data, size); return 0; }