• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef USE_ROSEN_DRAWING
30     const sk_sp<SkImage> rawImage;
31 #else
32     const std::shared_ptr<RSImage> rawImage;
33 #endif
34     auto ri = size % u16m;
35     std::string s(reinterpret_cast<const char*>(data), ri);
36     i = ImageSourceInfo(s);
37     ImageSourceInfo::IsSVGSource(s, InternalResource::ResourceId::SVG_START);
38     ImageSourceInfo::IsPngSource(s, InternalResource::ResourceId::SVG_START);
39     ImageSourceInfo::ResolveURIType(s);
40     ImageSourceInfo::IsValidBase64Head(s, "example");
41     ImageSourceInfo::IsUriOfDataAbilityEncoded(s, "example");
42     auto k = ImageCompressor::GetInstance();
43     Size s2;
44     ImageProvider::ResizeSkImage(rawImage, s, s2) ;
45 #ifndef USE_ROSEN_DRAWING
46     SkPixmap  pixmap;
47     sk_sp<SkData> compressdImage;
48 #else
49     RSBitmap rsBitmap;
50     std::shared_ptr<RSData> compressdImage;
51 #endif
52 #ifdef FUZZTEST
53     k->PartDoing();
54 #endif
55     k->GpuCompress(s, pixmap, 0, 0);
56 }
57 } // namespace OHOS::Ace
58 
59 using namespace OHOS;
60 using namespace OHOS::Ace;
61 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)62 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
63 {
64     MinorTest(data, size);
65     return 0;
66 }
67