mirror of
https://github.com/openharmony/graphic_graphic_surface.git
synced 2026-08-25 11:29:33 -04:00
44165b5d3f
Signed-off-by: s30029175 <shiqiwei4@huawei.com>
106 lines
3.7 KiB
C++
106 lines
3.7 KiB
C++
/*
|
|
* 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 "surfaceutils_fuzzer.h"
|
|
|
|
#include <securec.h>
|
|
#include <vector>
|
|
|
|
#include "data_generate.h"
|
|
#include "iconsumer_surface.h"
|
|
#include "surface.h"
|
|
#include "surface_utils.h"
|
|
|
|
using namespace g_fuzzCommon;
|
|
namespace OHOS {
|
|
namespace {
|
|
constexpr uint32_t MATRIX_SIZE = 16;
|
|
}
|
|
|
|
void FuzzTunnelLayerConfig(SurfaceUtils* utils)
|
|
{
|
|
std::string bundleName = GetStringFromData(STR_LEN);
|
|
std::string surfaceName = GetStringFromData(STR_LEN);
|
|
std::string queryBundleName = GetStringFromData(STR_LEN);
|
|
std::string querySurfaceName = GetStringFromData(STR_LEN);
|
|
std::string noDelimConfig = GetStringFromData(STR_LEN);
|
|
std::string extraSurfaceName = GetStringFromData(STR_LEN);
|
|
|
|
std::vector<std::string> tunnelConfigs = {
|
|
bundleName + "+" + surfaceName,
|
|
"+" + surfaceName,
|
|
bundleName + "+",
|
|
noDelimConfig,
|
|
bundleName + "+" + surfaceName + "+" + extraSurfaceName,
|
|
};
|
|
|
|
for (const auto& tunnelConfig : tunnelConfigs) {
|
|
utils->RemoveTunnelLayerConfig(tunnelConfig);
|
|
utils->AddTunnelLayerConfig(tunnelConfig);
|
|
utils->NeedForceTunnelLayer(surfaceName, bundleName);
|
|
utils->NeedForceTunnelLayer(querySurfaceName, queryBundleName);
|
|
utils->RemoveTunnelLayerConfig(tunnelConfig);
|
|
}
|
|
}
|
|
|
|
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
|
|
{
|
|
if (data == nullptr) {
|
|
return false;
|
|
}
|
|
|
|
// initialize
|
|
g_data = data;
|
|
g_size = size;
|
|
g_pos = 0;
|
|
|
|
// get data
|
|
uint64_t uniqueId1 = GetData<uint64_t>();
|
|
uint64_t uniqueId2 = GetData<uint64_t>();
|
|
uint64_t uniqueId3 = GetData<uint64_t>();
|
|
|
|
// test
|
|
sptr<OHOS::IConsumerSurface> cSurface = OHOS::IConsumerSurface::Create();
|
|
sptr<OHOS::IBufferProducer> producer = cSurface->GetProducer();
|
|
sptr<OHOS::Surface> pSurface = Surface::CreateSurfaceAsProducer(producer);
|
|
SurfaceUtils* utils = SurfaceUtils::GetInstance();
|
|
sptr<OHOS::Surface> surface = utils->GetSurface(uniqueId1);
|
|
utils->Add(uniqueId1, surface);
|
|
utils->Add(uniqueId2, pSurface);
|
|
utils->Remove(uniqueId3);
|
|
GraphicTransformType transformType = (GraphicTransformType)GetData<uint32_t>();
|
|
float matrix[MATRIX_SIZE];
|
|
for (int i = 0; i < MATRIX_SIZE; i++) {
|
|
matrix[i] = GetData<float>();
|
|
}
|
|
uint32_t matrixSize = MATRIX_SIZE;
|
|
Rect crop = GetData<Rect>();
|
|
sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
|
|
utils->ComputeTransformMatrix(matrix, matrixSize, buffer, transformType, crop);
|
|
utils->ComputeTransformMatrixV2(matrix, matrixSize, buffer, transformType, crop);
|
|
utils->GetNativeWindow(uniqueId1);
|
|
FuzzTunnelLayerConfig(utils);
|
|
return true;
|
|
}
|
|
} // namespace OHOS
|
|
|
|
/* Fuzzer entry point */
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
|
{
|
|
/* Run your code on data */
|
|
OHOS::DoSomethingInterestingWithMyAPI(data, size);
|
|
return 0;
|
|
}
|