Skip to content

Comments

Feat/fuzzing#243

Open
FloydZ wants to merge 20 commits intodevelopfrom
Feat/fuzzing
Open

Feat/fuzzing#243
FloydZ wants to merge 20 commits intodevelopfrom
Feat/fuzzing

Conversation

@FloydZ
Copy link
Collaborator

@FloydZ FloydZ commented Feb 12, 2025

Description

This PR contains

  • the possibility to run fuzzing tests
  • fixes for found issues with the fuzzer

Check

source .venv/bin/activate
pip install atheris
cd tests/fuzzing

python fuzz.py --bytes 1 --sd
python fuzz.py --bytes 1 --mq
python fuzz.py --bytes 1 --sdfq
python fuzz.py --bytes 1 --regsd
python fuzz.py --bytes 1 --pk
python fuzz.py --bytes 1 --lw
python fuzz.py --bytes 1 --pe
python fuzz.py --bytes 1 --mr
python fuzz.py --bytes 1 --uov
python fuzz.py --bytes 1 --mayo

python fuzz.py --sd
python fuzz.py --mq
python fuzz.py --sdfq
python fuzz.py --regsd
python fuzz.py --pk
python fuzz.py --lw
python fuzz.py --pe
python fuzz.py --mr
python fuzz.py --uov
python fuzz.py --mayo

Docker Setup:

make docker-fuzzing
docker run --rm cf-fuzzer ./tests/fuzzing/fuzz.py --sd

@FloydZ FloydZ mentioned this pull request Feb 12, 2025
@sonarqubecloud
Copy link

@Dioprz Dioprz marked this pull request as draft February 15, 2025 23:24
@Dioprz
Copy link
Collaborator

Dioprz commented Feb 15, 2025

(I changed this to a draft to avoid accidental merging)

After some reads about Atheris and fuzzy testing, this sounds very interesting. Happy to learn about its existence.

Let me know if I can help with something here, @FloydZ.

@FloydZ
Copy link
Collaborator Author

FloydZ commented Feb 16, 2025

Hi @Dioprz ,
currently I'm not really 100% happy with the solution. There are two main issues:

  • atheris only allows for a single function to be fuzzed at each time. Thats why I have code like:
#atheris.Setup(sys.argv, SDFuzz)
...
atheris.Setup(sys.argv, RankSDFuzz)
...
#atheris.Setup(sys.argv, MAYOFuzz)

And you need enable/disable the estimator by hand. If you know how to circumvent that, without adding a bash script, which calls the python code multiple times. let me know.
The second problem is the exception handling. At first I thought catching ValueError is enough to separate between "real problematic" errors in the code, and errors which are already caught by the class constructor. But turns out errors like log2(0) are also ValueErrors, hence I have this ugly:

if type(e) != ValueError or str(e) == "math domain error":

check to difference between those two. If you have a better solution for this, I would really appreciate it. Plus Im not 100% that this is actually really correct.

@FloydZ FloydZ marked this pull request as ready for review May 29, 2025 14:38
@FloydZ FloydZ requested review from Dioprz, Javierverbel and Memphisd and removed request for Dioprz and Memphisd May 29, 2025 14:38
@FloydZ
Copy link
Collaborator Author

FloydZ commented Jun 9, 2025

Apparently, sonar cloud thinks that:

if w <= 0 or k <= 0:

always evaluates to false, for what ever reason.

@Dioprz
Copy link
Collaborator

Dioprz commented Jun 10, 2025

Apparently, sonar cloud thinks that:

if w <= 0 or k <= 0:

always evaluates to false, for what ever reason.

The full code snippet failing (well, one of them) is this one:

    def __init__(self, n: int, k: int, w: int, **kwargs):
        super().__init__(**kwargs)
        if k <= 0 or n <= 0 or w <= 0:
            raise ValueError("n, k, w must be positive integers")
        if k > n:
            raise ValueError("k must be smaller or equal to n")
        if w > n - k:
            raise ValueError("w must be smaller or equal to n-k")
        if w <= 0 or k <= 0:
            raise ValueError("w and k must be at least 1")

And looking at it... I think it makes sense because you will never be able to reach the last if branch, as the same conditions will trigger the first if branch. Makes sense, or I'm overlooking something?

Javierverbel
Javierverbel previously approved these changes Jun 18, 2025
@FloydZ
Copy link
Collaborator Author

FloydZ commented Jun 23, 2025

updated PR. Can be reviewed

@Javierverbel Javierverbel self-requested a review June 24, 2025 07:10
Javierverbel
Javierverbel previously approved these changes Jun 24, 2025
@Memphisd
Copy link
Collaborator

I think this atheris library should be preinstalled in the dev-docker. It seems rather elaborate to install it, on Mac at least.

@Javierverbel Javierverbel self-requested a review July 1, 2025 04:53
Copy link
Collaborator

@Javierverbel Javierverbel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second command doesn't work for me. I get

Unable to find image 'cf-fuzzer:latest' locally
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "./tests/fuzzing/fuzz.py": permission denied: unknown.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 2, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants