Skip to content
New issue

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

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

Already on GitHub? # to your account

Add a fuzzer target #475

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
60 changes: 60 additions & 0 deletions fuzz/test_differential_fuzzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import sys
import math
import os
import pytest

from msgpack import _cmsgpack, fallback


def replace_nan(data, sentinel):
if type(data) == float and math.isnan(data):
return sentinel
if type(data) == list:
return [replace_nan(x, sentinel) for x in data]
if type(data) == dict:
return {k: replace_nan(v, sentinel) for k, v in data.items()}
return data


def TestOneInput(data):
try:
from_extension = _cmsgpack.unpackb(data)
except:
return
try:
from_fallback = fallback.unpackb(data)
except:
return
sentinel = object()
if replace_nan(from_extension, sentinel) != replace_nan(from_fallback, sentinel):
raise RuntimeError(
f"Decoding disagreement: input: {data}, from extension: {from_extension}, from fallback: {from_fallback}"
)


SCRIPT_DIR = os.path.dirname(__file__)
CORPUS_DIR = os.path.join(SCRIPT_DIR, "test_differential_fuzzer_seed_corpus")
if os.path.exists(CORPUS_DIR):
CORPUS = [
open(os.path.join(CORPUS_DIR, f), "rb").read() for f in os.listdir(CORPUS_DIR)
]
else:
# When this file is executed as a fuzz target the dirrectory
# test_differential_fuzzer_seed_corpus does not exist
CORPUS = []


@pytest.mark.parametrize("data", CORPUS)
def test_try_the_seed_corpus(data):
TestOneInput(data)


def main():
import atheris

atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions fuzz/test_differential_fuzzer_seed_corpus/EmptyArray.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 change: 1 addition & 0 deletions fuzz/test_differential_fuzzer_seed_corpus/EmptyObject.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
��������� �
� � �������������������� �!�"�#�$�%�&�'�(�)�*�+�,�-�.�/�0�1�2�3�4�5�6�7�8�9�:�;�<�=�>�?�@�A�B�C�D�E�F�G�H�I�J�K�L�M�N�O�P�Q�R�S�T�U�V�W�X�Y�Z�[�\�]�^�_�`�a�b�c�d�e�f�g�h�i�j�k�l�m�n�o�p�q�r�s�t�u�v�w�x
Expand Down
Binary file not shown.
Binary file not shown.