Flutter Engine
The Flutter Engine
FuzzAndroidCodec.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2018 Google, LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
14
15#include "fuzz/Fuzz.h"
16
17bool FuzzAndroidCodec(const uint8_t *fuzzData, size_t fuzzSize, uint8_t sampleSize) {
18 auto codec = SkAndroidCodec::MakeFromStream(SkMemoryStream::MakeDirect(fuzzData, fuzzSize));
19 if (!codec) {
20 return false;
21 }
22
23 auto size = codec->getSampledDimensions(sampleSize);
25 SkBitmap bm;
26 if (!bm.tryAllocPixels(info)) {
27 // May fail in memory-constrained fuzzing environments
28 return false;
29 }
30
32 options.fSampleSize = sampleSize;
33
34 auto result = codec->getAndroidPixels(bm.info(), bm.getPixels(), bm.rowBytes(), &options);
35 switch (result) {
39 break;
40 default:
41 return false;
42 }
43
44 SkGainmapInfo gainmapInfo;
45 auto gainmapImageStream = std::unique_ptr<SkStream>();
46
47 if (codec->getAndroidGainmap(&gainmapInfo, &gainmapImageStream)) {
48 // Do something with the outputs so the compiler does not optimize the call away.
49 if (!std::isfinite(gainmapInfo.fDisplayRatioSdr)) {
50 return false;
51 }
52 if (gainmapImageStream->getLength() > 100000000) {
53 return false;
54 }
55 }
56
58 if (!surface) {
59 // May return nullptr in memory-constrained fuzzing environments
60 return false;
61 }
62
63 surface->getCanvas()->drawImage(bm.asImage(), 0, 0);
64 return true;
65}
66
67#if defined(SK_BUILD_FOR_LIBFUZZER)
68extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
69 if (size > 10240) {
70 return 0;
71 }
72 Fuzz fuzz(data, size);
73 uint8_t sampleSize;
74 fuzz.nextRange(&sampleSize, 1, 64);
75 FuzzAndroidCodec(fuzz.remainingData(), fuzz.remainingSize(), sampleSize);
76 return 0;
77}
78#endif
const char * options
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
bool FuzzAndroidCodec(const uint8_t *fuzzData, size_t fuzzSize, uint8_t sampleSize)
Definition: Fuzz.h:24
static std::unique_ptr< SkAndroidCodec > MakeFromStream(std::unique_ptr< SkStream >, SkPngChunkReader *=nullptr)
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
size_t rowBytes() const
Definition: SkBitmap.h:238
void * getPixels() const
Definition: SkBitmap.h:283
const SkImageInfo & info() const
Definition: SkBitmap.h:139
bool tryAllocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:271
@ kIncompleteInput
Definition: SkCodec.h:84
@ kSuccess
Definition: SkCodec.h:80
@ kErrorInInput
Definition: SkCodec.h:91
static std::unique_ptr< SkMemoryStream > MakeDirect(const void *data, size_t length)
Definition: SkStream.cpp:310
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
VkSurfaceKHR surface
Definition: main.cc:49
GAsyncResult * result
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SINT bool isfinite(const Vec< N, T > &v)
Definition: SkVx.h:1003
float fDisplayRatioSdr
Definition: SkGainmapInfo.h:65
static SkImageInfo MakeN32Premul(int width, int height)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63