Skip to content

Added fuzzer to be run with OSS-Fuzz #772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CIFuzz
on: [pull_request]
jobs:
Fuzzing:
runs-on: ubuntu-latest
steps:
- name: Build Fuzzers
id: build
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
with:
oss-fuzz-project-name: 'jsonschema'
dry-run: false
continue-on-error: true
- name: Run Fuzzers
if: steps.build.outcome == 'success'
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
with:
oss-fuzz-project-name: 'jsonschema'
fuzz-seconds: 30
dry-run: false
- name: Upload Crash
uses: actions/upload-artifact@v1
if: failure() && steps.build.outcome == 'success'
with:
name: artifacts
path: ./out/artifacts
39 changes: 39 additions & 0 deletions jsonschema/tests/fuzz_validate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sys

from hypothesis import given
from hypothesis import strategies as st
import atheris

import jsonschema

PRIM = st.one_of(
st.booleans(),
st.integers(min_value=-(2 ** 63), max_value=2 ** 63 - 1),
st.floats(allow_nan=False, allow_infinity=False),
st.text(),
)
DICT = st.recursive(
base=st.dictionaries(st.text(), PRIM),
extend=lambda inner: st.dictionaries(st.text(), inner),
)


@given(obj1=DICT, obj2=DICT)
def test_schemas(obj1, obj2):
try:
jsonschema.validate(instance=obj1, schema=obj2)
except jsonschema.exceptions.ValidationError:
None
except jsonschema.exceptions.SchemaError:
None


def main():
atheris.Setup(sys.argv,
test_schemas.hypothesis.fuzz_one_input,
enable_python_coverage=True)
atheris.Fuzz()


if __name__ == "__main__":
main()