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 "imageApi_fuzzer.h"
17
18 #include "core/image/image_cache.h"
19 #include "core/image/image_compressor.h"
20 #include "core/image/image_loader.h"
21 #include "core/image/image_object.h"
22 #include "core/image/image_provider.h"
23
24 namespace OHOS::Ace {
25 const uint32_t u16m = 65535;
MinorTest(const uint8_t * data,size_t size)26 void MinorTest(const uint8_t* data, size_t size)
27 {
28 OHOS::Ace::ImageSourceInfo i;
29 const sk_sp<SkImage> rawImage;
30 auto ri = size % u16m;
31 std::string s(reinterpret_cast<const char*>(data), ri);
32 i = ImageSourceInfo(s);
33 ImageSourceInfo::IsSVGSource(s, InternalResource::ResourceId::SVG_START);
34 ImageSourceInfo::IsPngSource(s, InternalResource::ResourceId::SVG_START);
35 ImageSourceInfo::ResolveURIType(s);
36 ImageSourceInfo::IsValidBase64Head(s, "example");
37 ImageSourceInfo::IsUriOfDataAbilityEncoded(s, "example");
38 auto k = ImageCompressor::GetInstance();
39 Size s2;
40 ImageProvider::ResizeSkImage(rawImage, s, s2) ;
41 SkPixmap pixmap;
42 sk_sp<SkData> compressdImage;
43 #ifdef FUZZTEST
44 k->PartDoing();
45 #endif
46 k->GpuCompress(s, pixmap, 0, 0);
47 }
48 } // namespace OHOS::Ace
49
50 using namespace OHOS;
51 using namespace OHOS::Ace;
52 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)53 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
54 {
55 MinorTest(data, size);
56 return 0;
57 }
58