Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
chrome_fuzz.cpp File Reference
#include "include/core/SkCanvas.h"
#include "SkFlattenableSerialization.h"
#include "include/core/SkImageFilter.h"
#include "include/core/SkString.h"
#include "src/core/SkOSFile.h"
#include <stdio.h>

Go to the source code of this file.

Functions

static bool read_test_case (const char *filename, SkString *testdata)
 
static void run_test_case (const SkString &testdata, const SkBitmap &bitmap, SkCanvas *canvas)
 
static bool read_and_run_test_case (const char *filename, const SkBitmap &bitmap, SkCanvas *canvas)
 
int main (int argc, char **argv)
 

Variables

static const int kBitmapSize = 24
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 70 of file chrome_fuzz.cpp.

70 {
71 int ret = 0;
73 bitmap.allocN32Pixels(kBitmapSize, kBitmapSize);
74 SkCanvas canvas(bitmap);
75 canvas.clear(0x00000000);
76 for (int i = 1; i < argc; i++)
77 if (!read_and_run_test_case(argv[i], bitmap, &canvas))
78 ret = 2;
79 // Cluster-Fuzz likes "#EOF" as the last line of output to help distinguish
80 // successful runs from crashes.
81 SkDebugf("#EOF\n");
82 return ret;
83}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static bool read_and_run_test_case(const char *filename, const SkBitmap &bitmap, SkCanvas *canvas)
static const int kBitmapSize

◆ read_and_run_test_case()

static bool read_and_run_test_case ( const char *  filename,
const SkBitmap bitmap,
SkCanvas canvas 
)
static

Definition at line 59 of file chrome_fuzz.cpp.

60 {
61 SkString testdata;
62 SkDebugf("Test case: %s\n", filename);
63 // read_test_case will print a useful error message if it fails.
64 if (!read_test_case(filename, &testdata))
65 return false;
66 run_test_case(testdata, bitmap, canvas);
67 return true;
68}
static bool read_test_case(const char *filename, SkString *testdata)
static void run_test_case(const SkString &testdata, const SkBitmap &bitmap, SkCanvas *canvas)

◆ read_test_case()

static bool read_test_case ( const char *  filename,
SkString testdata 
)
static

Definition at line 15 of file chrome_fuzz.cpp.

15 {
16 FILE* file = sk_fopen(filename, kRead_SkFILE_Flag);
17 if (!file) {
18 SkDebugf("couldn't open file %s\n", filename);
19 return false;
20 }
21 size_t len = sk_fgetsize(file);
22 if (!len) {
23 SkDebugf("couldn't read file %s\n", filename);
24 return false;
25 }
26 testdata->resize(len);
27 (void) fread(testdata->data(), len, file);
28 return true;
29}
FILE * sk_fopen(const char path[], SkFILE_Flags)
@ kRead_SkFILE_Flag
Definition SkOSFile.h:20
size_t sk_fgetsize(FILE *)
const char * data() const
Definition SkString.h:132
void resize(size_t len)
Definition SkString.cpp:374

◆ run_test_case()

static void run_test_case ( const SkString testdata,
const SkBitmap bitmap,
SkCanvas canvas 
)
static

Definition at line 31 of file chrome_fuzz.cpp.

32 {
33 // This call shouldn't crash or cause ASAN to flag any memory issues
34 // If nothing bad happens within this call, everything is fine
35 sk_sp<SkImageFilter> flattenable = SkValidatingDeserializeImageFilter(testdata.c_str(),
36 testdata.size());
37
38 // Adding some info, but the test passed if we got here without any trouble
39 if (flattenable != nullptr) {
40 SkDebugf("Valid stream detected.\n");
41 // Let's see if using the filters can cause any trouble...
43 paint.setImageFilter(flattenable);
44 canvas->save();
47
48 // This call shouldn't crash or cause ASAN to flag any memory issues
49 // If nothing bad happens within this call, everything is fine
50 canvas->drawBitmap(bitmap, 0, 0, &paint);
51
52 SkDebugf("Filter DAG rendered successfully.\n");
53 canvas->restore();
54 } else {
55 SkDebugf("Invalid stream detected.\n");
56 }
57}
#define SkIntToScalar(x)
Definition SkScalar.h:57
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void restore()
Definition SkCanvas.cpp:465
int save()
Definition SkCanvas.cpp:451
size_t size() const
Definition SkString.h:131
const char * c_str() const
Definition SkString.h:133
const Paint & paint
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659

Variable Documentation

◆ kBitmapSize

const int kBitmapSize = 24
static

Definition at line 13 of file chrome_fuzz.cpp.