forked from google/oss-fuzz
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Python projects #14
Open
ethanbwang
wants to merge
3
commits into
master
Choose a base branch
from
python_projects
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Python projects #14
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,48 @@ | ||
#!/usr/bin/python3 | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import sys | ||
import atheris | ||
|
||
import black | ||
|
||
from py_io_capture import decorate_module, dump_records, DUMP_FILE_NAME | ||
import atexit | ||
black = decorate_module(black) | ||
atexit.register(dump_records, DUMP_FILE_NAME) | ||
|
||
def TestOneInput(data): | ||
fdp = atheris.FuzzedDataProvider(data) | ||
try: | ||
black.format_file_contents(fdp.ConsumeUnicodeNoSurrogates(sys.maxsize), | ||
mode=black.Mode(), | ||
fast=fdp.ConsumeBool()) | ||
except black.InvalidInput: | ||
pass | ||
except black.NothingChanged: | ||
pass | ||
except AssertionError: | ||
pass | ||
except KeyError: | ||
pass | ||
|
||
|
||
def main(): | ||
atheris.instrument_all() | ||
atheris.Setup(sys.argv, TestOneInput) | ||
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,44 @@ | ||
#!/usr/bin/python3 | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import sys | ||
import atheris | ||
|
||
import black | ||
|
||
from py_io_capture import decorate_module, dump_records, DUMP_FILE_NAME | ||
import atexit | ||
black = decorate_module(black) | ||
atexit.register(dump_records, DUMP_FILE_NAME) | ||
|
||
def TestOneInput(data): | ||
fdp = atheris.FuzzedDataProvider(data) | ||
try: | ||
black.lib2to3_parse(fdp.ConsumeUnicodeNoSurrogates(sys.maxsize)) | ||
except black.InvalidInput: | ||
pass | ||
except AssertionError: | ||
pass | ||
except KeyError: | ||
pass | ||
|
||
|
||
def main(): | ||
atheris.instrument_all() | ||
atheris.Setup(sys.argv, TestOneInput) | ||
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,49 @@ | ||
#!/usr/bin/python3 | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import sys | ||
import atheris | ||
|
||
import black | ||
|
||
from py_io_capture import decorate_module, dump_records, DUMP_FILE_NAME | ||
import atexit | ||
black = decorate_module(black) | ||
atexit.register(dump_records, DUMP_FILE_NAME) | ||
|
||
def TestOneInput(data): | ||
if len(data) < 50: | ||
return | ||
|
||
fdp = atheris.FuzzedDataProvider(data) | ||
try: | ||
black.format_file_contents(fdp.ConsumeUnicodeNoSurrogates(sys.maxsize), | ||
mode=black.Mode(), | ||
fast=False) | ||
except black.InvalidInput: | ||
pass | ||
except black.NothingChanged: | ||
pass | ||
except AssertionError: | ||
pass | ||
|
||
|
||
def main(): | ||
atheris.instrument_all() | ||
atheris.Setup(sys.argv, TestOneInput) | ||
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,97 @@ | ||
#!/usr/bin/python3 | ||
# Copyright 2022 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Scalar equivalene checker""" | ||
|
||
import os | ||
import sys | ||
import atheris | ||
|
||
import numpy as np | ||
from numpy.testing import assert_array_almost_equal | ||
import bottleneck as bn | ||
|
||
from py_io_capture import decorate_module, dump_records, DUMP_FILE_NAME | ||
import atexit | ||
bn = decorate_module(bn) | ||
atexit.register(dump_records, DUMP_FILE_NAME) | ||
|
||
def gen_random_array(data, fdp = None): | ||
if fdp is None: | ||
fdp = atheris.FuzzedDataProvider(data) | ||
l1 = list() | ||
for i in range(fdp.ConsumeIntInRange(5, 3000)): | ||
l1.append(fdp.ConsumeIntInRange(1,10000)) | ||
a = np.array(l1) | ||
return a | ||
|
||
def TestOneInput(data): | ||
"""Tests scalar equivalence and also move operations""" | ||
fdp = atheris.FuzzedDataProvider(data) | ||
a = gen_random_array(data, fdp) | ||
|
||
func_pairs = [ | ||
(bn.nansum, bn.slow.nansum), | ||
(bn.nanmean, bn.slow.nanmean), | ||
(bn.nanstd, bn.slow.nanstd), | ||
(bn.nanvar, bn.slow.nanvar), | ||
(bn.nanmin, bn.slow.nanmin), | ||
(bn.median, bn.slow.median), | ||
(bn.nanmedian, bn.slow.nanmedian), | ||
(bn.ss, bn.slow.ss), | ||
(bn.nanargmin, bn.slow.nanargmin), | ||
(bn.nanargmax, bn.slow.nanargmax), | ||
(bn.anynan, bn.slow.anynan), | ||
(bn.allnan, bn.slow.allnan), | ||
] | ||
|
||
idx = 0 | ||
for func0, func1 in func_pairs: | ||
idx = idx + 1 | ||
actual = func0(a) | ||
desired = func1(a) | ||
assert_array_almost_equal( | ||
actual, | ||
desired, | ||
err_msg="Failed scalar equivalence" | ||
) | ||
|
||
|
||
# Test move operations | ||
window = fdp.ConsumeIntInRange(2, 50) | ||
min_count = fdp.ConsumeIntInRange(1, window) | ||
actual = bn.move_median( | ||
a, | ||
window=window, | ||
min_count = fdp.ConsumeIntInRange(1,100) | ||
) | ||
desired = bn.slow.move_median( | ||
a, | ||
window=window, | ||
min_count=fdp.ConsumeIntInRange(1, 100) | ||
) | ||
assert_array_almost_equal( | ||
actual, | ||
desired, | ||
err_msg="Failed move operation" | ||
) | ||
|
||
|
||
def main(): | ||
atheris.instrument_all() | ||
atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True) | ||
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,46 @@ | ||
#!/usr/bin/python3 | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import sys | ||
import atheris | ||
|
||
import bz2file | ||
|
||
from py_io_capture import decorate_module, dump_records, DUMP_FILE_NAME | ||
import atexit | ||
bz2file = decorate_module(bz2file) | ||
atexit.register(dump_records, DUMP_FILE_NAME) | ||
|
||
def TestOneInput(data): | ||
fdp = atheris.FuzzedDataProvider(data) | ||
bzfile_path = '/tmp/random_file.txt' | ||
with open(bzfile_path, 'wb') as f: | ||
f.write(fdp.ConsumeBytes(sys.maxsize)) | ||
|
||
try: | ||
with bz2file.open(bzfile_path) as target_file: | ||
target_file.seek(fdp.ConsumeIntInRange(-1, 100)) | ||
target_file.read(size=fdp.ConsumeIntInRange(-1, 100)) | ||
except (ValueError,EOFError,OSError): | ||
pass | ||
|
||
|
||
def main(): | ||
atheris.instrument_all() | ||
atheris.Setup(sys.argv, TestOneInput) | ||
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,49 @@ | ||
#!/usr/bin/python3 | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import sys | ||
import atheris | ||
|
||
from cffi import FFI, VerificationError, FFIError, CDefError | ||
from cffi import recompiler | ||
|
||
from py_io_capture import decorate_module, dump_records, DUMP_FILE_NAME | ||
import atexit | ||
cffi = decorate_module(cffi) | ||
atexit.register(dump_records, DUMP_FILE_NAME) | ||
|
||
def TestOneInput(data): | ||
fdp = atheris.FuzzedDataProvider(data) | ||
ffi = FFI() | ||
try: | ||
ffi.cdef(fdp.ConsumeUnicodeNoSurrogates(sys.maxsize)) | ||
recomp = recompiler.Recompiler(ffi, 'fuzzmod') | ||
|
||
# Call functions on the recompiler object. | ||
recomp.collect_type_table() | ||
recomp.collect_step_tables() | ||
except (VerificationError, FFIError, CDefError) as e: | ||
pass | ||
except AssertionError: | ||
pass | ||
|
||
|
||
def main(): | ||
atheris.instrument_all() | ||
atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True) | ||
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,47 @@ | ||
#!/usr/bin/python3 | ||
# Copyright 2022 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import sys | ||
import atheris | ||
import chardet | ||
|
||
from py_io_capture import decorate_module, dump_records, DUMP_FILE_NAME | ||
import atexit | ||
chardet = decorate_module(chardet) | ||
atexit.register(dump_records, DUMP_FILE_NAME) | ||
|
||
def TestOneInput(data): | ||
fdp = atheris.FuzzedDataProvider(data) | ||
|
||
# General detection. | ||
chardet.detect(data) | ||
|
||
# Incremental feeding> | ||
detector = chardet.universaldetector.UniversalDetector() | ||
for b in data: | ||
detector.feed(b) | ||
if detector.done: | ||
break | ||
detector.close() | ||
res = detector.result | ||
|
||
|
||
def main(): | ||
atheris.instrument_all() | ||
atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True) | ||
atheris.Fuzz() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is no
import cffi
, this decoration will case error. We can either decoraterecompiler
or addimport cffi
to the top