-
Notifications
You must be signed in to change notification settings - Fork 138
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
Showing
5 changed files
with
92 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Copyright (C) 2023 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: MIT |
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,15 @@ | ||
"convert" | ||
"detect" | ||
"compare" | ||
"dinfo" | ||
"download" | ||
"explain" | ||
"explore" | ||
"filter" | ||
"generate" | ||
"merge" | ||
"patch" | ||
"prune" | ||
"stats" | ||
"transform" | ||
"validate" |
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,44 @@ | ||
# Copyright (C) 2023 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: MIT | ||
import sys | ||
|
||
import atheris | ||
from helper import FuzzingHelper | ||
|
||
from datumaro.__main__ import main as cli_main | ||
from datumaro.cli.util.errors import CliException | ||
|
||
|
||
@atheris.instrument_func | ||
def fuzz_datum(input_bytes): | ||
# create a FuzzingHelper instance to get suitable data type from the randomly generated 'input_bytes' | ||
helper = FuzzingHelper(input_bytes) | ||
backup_argv = sys.argv | ||
|
||
# get 'operation' arguments from 'input_bytes' | ||
operation = helper.get_string() | ||
sys.argv = ["datum", operation] | ||
try: | ||
_ = cli_main() | ||
except SystemExit as e: | ||
# argparser will throw SystemExit with code 2 when some required arguments are missing | ||
if e.code != 2: | ||
raise | ||
except CliException: | ||
pass | ||
# some known exceptions can be catched here | ||
finally: | ||
sys.argv = backup_argv | ||
|
||
|
||
def main(): | ||
# 'sys.argv' used to passing options to atheris.Setup() | ||
# available options can be found https://llvm.org/docs/LibFuzzer.html#options | ||
atheris.Setup(sys.argv, fuzz_datum) | ||
# Fuzz() will | ||
atheris.Fuzz() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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 @@ | ||
# Copyright (C) 2023 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: MIT | ||
import atheris | ||
|
||
|
||
class FuzzingHelper(object): | ||
"""Helper to make required data from input_bytes for the fuzzing tests""" | ||
|
||
def __init__(self, input_bytes): | ||
"""Init""" | ||
self.provider = atheris.FuzzedDataProvider(input_bytes) | ||
|
||
def get_string(self, byte_conut=256): | ||
"""Consume a string""" | ||
return self.provider.ConsumeString(byte_conut) |
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