Details
Details
- Reviewers
indygreg - Group Reviewers
hg-reviewers - Commits
- rHG78df32a8b6f4: fuzz: migrate xdiff fuzzer to use FuzzedDataProvider
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
| indygreg |
| hg-reviewers |
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | contrib/fuzz/xdiff.cc (18 lines) |
| Commit | Parents | Author | Summary | Date |
|---|---|---|---|---|
| e6858b616f47 | 3a90e6f74914 | Augie Fackler | Nov 11 2019, 4:37 PM |
| /* | /* | ||||
| * xdiff.cc - fuzzer harness for thirdparty/xdiff | * xdiff.cc - fuzzer harness for thirdparty/xdiff | ||||
| * | * | ||||
| * Copyright 2018, Google Inc. | * Copyright 2018, Google Inc. | ||||
| * | * | ||||
| * This software may be used and distributed according to the terms of | * This software may be used and distributed according to the terms of | ||||
| * the GNU General Public License, incorporated herein by reference. | * the GNU General Public License, incorporated herein by reference. | ||||
| */ | */ | ||||
| #include "thirdparty/xdiff/xdiff.h" | #include "thirdparty/xdiff/xdiff.h" | ||||
| #include <inttypes.h> | #include <inttypes.h> | ||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include "fuzzutil.h" | #include <fuzzer/FuzzedDataProvider.h> | ||||
| extern "C" { | extern "C" { | ||||
| int hunk_consumer(long a1, long a2, long b1, long b2, void *priv) | int hunk_consumer(long a1, long a2, long b1, long b2, void *priv) | ||||
| { | { | ||||
| // TODO: probably also test returning -1 from this when things break? | // TODO: probably also test returning -1 from this when things break? | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) | int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) | ||||
| { | { | ||||
| // Don't allow fuzzer inputs larger than 100k, since we'll just bog | // Don't allow fuzzer inputs larger than 100k, since we'll just bog | ||||
| // down and not accomplish much. | // down and not accomplish much. | ||||
| if (Size > 100000) { | if (Size > 100000) { | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| auto maybe_inputs = SplitInputs(Data, Size); | FuzzedDataProvider provider(Data, Size); | ||||
| if (!maybe_inputs) { | std::string left = provider.ConsumeRandomLengthString(Size); | ||||
| return 0; | std::string right = provider.ConsumeRemainingBytesAsString(); | ||||
| } | |||||
| auto inputs = std::move(maybe_inputs.value()); | |||||
| mmfile_t a, b; | mmfile_t a, b; | ||||
| a.ptr = inputs.left.get(); | a.ptr = (char *)left.c_str(); | ||||
| a.size = inputs.left_size; | a.size = left.size(); | ||||
| b.ptr = inputs.right.get(); | b.ptr = (char *)right.c_str(); | ||||
| b.size = inputs.right_size; | b.size = right.size(); | ||||
| xpparam_t xpp = { | xpparam_t xpp = { | ||||
| XDF_INDENT_HEURISTIC, /* flags */ | XDF_INDENT_HEURISTIC, /* flags */ | ||||
| }; | }; | ||||
| xdemitconf_t xecfg = { | xdemitconf_t xecfg = { | ||||
| XDL_EMIT_BDIFFHUNK, /* flags */ | XDL_EMIT_BDIFFHUNK, /* flags */ | ||||
| hunk_consumer, /* hunk_consume_func */ | hunk_consumer, /* hunk_consume_func */ | ||||
| }; | }; | ||||
| xdemitcb_t ecb = { | xdemitcb_t ecb = { | ||||