-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94e7336
commit f051125
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# If google/oss-fuzz has set the fuzzing engine | ||
if(DEFINED ENV{LIB_FUZZING_ENGINE}) | ||
set(FUZZING_ENGINE $ENV{LIB_FUZZING_ENGINE}) | ||
set(FUZZING_COMPILE_FLAGS "") | ||
set(FUZZING_LINK_FLAGS "${FUZZING_ENGINE}") | ||
else() | ||
set(FUZZING_COMPILE_FLAGS "-fsanitize=fuzzer") | ||
set(FUZZING_LINK_FLAGS "-fsanitize=fuzzer") | ||
endif() | ||
|
||
add_executable(fuzz_layout fuzz_layout.cpp) | ||
set_target_properties(fuzz_layout PROPERTIES | ||
COMPILE_FLAGS "${FUZZING_COMPILE_FLAGS}" | ||
LINK_FLAGS "${FUZZING_LINK_FLAGS}" | ||
) | ||
target_link_libraries(fuzz_layout yogacore) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <fuzzer/FuzzedDataProvider.h> | ||
#include <cstdint> | ||
#include <yoga/Yoga.h> | ||
|
||
YGFlexDirection fuzzed_flex_direction(FuzzedDataProvider &fdp) { | ||
return fdp.PickValueInArray({ | ||
YGFlexDirectionColumn, | ||
YGFlexDirectionColumnReverse, | ||
YGFlexDirectionRow, | ||
YGFlexDirectionRowReverse, | ||
}); | ||
} | ||
|
||
void FillFuzzedTree(FuzzedDataProvider &fdp, const YGConfigRef &config, const YGNodeRef &root, size_t depth = 0) { | ||
constexpr size_t kMaxDepth = 20; | ||
constexpr size_t kMaxChildren= 20; | ||
|
||
if(depth > kMaxDepth) { | ||
return; | ||
} | ||
|
||
size_t children = fdp.ConsumeIntegralInRange<size_t>(0, kMaxChildren); | ||
for(size_t i = 0; i < children; i++) { | ||
const YGNodeRef child = YGNodeNewWithConfig(config); | ||
YGNodeStyleSetFlexDirection(root, fuzzed_flex_direction(fdp)); | ||
YGNodeStyleSetWidth(child, fdp.ConsumeFloatingPoint<float>()); | ||
YGNodeStyleSetGap(child, YGGutterAll, fdp.ConsumeProbability<float>()*100); | ||
YGNodeStyleSetHeight(child, fdp.ConsumeFloatingPoint<float>()); | ||
YGNodeInsertChild(root, child, i); | ||
FillFuzzedTree(fdp, config, child, depth + 1); | ||
} | ||
} | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | ||
FuzzedDataProvider fdp(data,size); | ||
const YGConfigRef config = YGConfigNew(); | ||
const YGNodeRef root = YGNodeNewWithConfig(config); | ||
FillFuzzedTree(fdp, config, root); | ||
|
||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); | ||
|
||
YGNodeFreeRecursive(root); | ||
YGConfigFree(config); | ||
return 0; | ||
} |