• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 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 
8 #include "src/core/SkDescriptor.h"
9 #include "src/core/SkReadBuffer.h"
10 
FuzzSkDescriptorDeserialize(sk_sp<SkData> bytes)11 void FuzzSkDescriptorDeserialize(sk_sp<SkData> bytes) {
12     SkReadBuffer buffer{bytes->data(), bytes->size()};
13     auto sut = SkAutoDescriptor::MakeFromBuffer(buffer);
14     if (!sut.has_value()) {
15         return;
16     }
17 
18     auto desc = sut->getDesc();
19 
20     desc->computeChecksum();
21     desc->isValid();
22 
23     // An arbitrary number
24     uint32_t tagToFind = 117;
25 
26     uint32_t ignore;
27     desc->findEntry(tagToFind, &ignore);
28 }
29 
30 #if defined(SK_BUILD_FOR_LIBFUZZER)
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)31 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
32     if (size > 1024) {
33         return 0;
34     }
35     auto bytes = SkData::MakeWithoutCopy(data, size);
36     FuzzSkDescriptorDeserialize(bytes);
37     return 0;
38 }
39 #endif
40