Skip to content
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

[red-knot] Add fuzzer to catch panics for invalid syntax #14678

Merged
merged 4 commits into from
Dec 4, 2024

Conversation

dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Nov 29, 2024

Summary

This PR adds a fuzzer harness for red knot that runs the type checker on source code that contains invalid syntax.

Additionally, this PR also updates the init-fuzzer.sh script to increase the corpus size to:

  • Include various crates that includes Python source code
  • Use the 3.13 CPython source code

And, remove any non-Python files from the final corpus so that when the fuzzer tries to minify the corpus, it doesn't produce files that only contains documentation content as that's just noise.

Test Plan

Run ./fuzz/init-fuzzer.sh, say no to the large dataset.
Run the fuzzer with cargo +night fuzz run red_knot_check_invalid_syntax -- -timeout=5

@dhruvmanila dhruvmanila added the red-knot Multi-file analysis & type inference label Nov 29, 2024
@dhruvmanila dhruvmanila force-pushed the dhruv/red-knot-fuzzer branch from aa40db7 to 94698f8 Compare December 3, 2024 06:09
@dhruvmanila dhruvmanila force-pushed the dhruv/red-knot-fuzzer branch from 94698f8 to 4df8284 Compare December 3, 2024 06:14
Copy link
Contributor

github-actions bot commented Dec 3, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@dhruvmanila dhruvmanila marked this pull request as ready for review December 3, 2024 11:02
cp -r "../../../crates/ruff_python_parser/resources" "ruff_python_parser"

# Delete all non-Python files
find . -type f -not -name "*.py" -delete
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also keep stub files?

Using

Suggested change
find . -type f -not -name "*.py" -delete
find . -type f -not \( -name "*.py" -or -name "*.pyi" \) -delete

or

Suggested change
find . -type f -not -name "*.py" -delete
find . -type f -not -regex '.*\.pyi?' -delete

Copy link
Member Author

Choose a reason for hiding this comment

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

We could but at the end we would still use a .py file even if the content is coming from a stub file. The reason is that the fuzzer gives us the raw bytes of the source code that it generates.

Hmm, maybe we should run red knot once on a .py file and then on a .pyi file with the same content as we do on the corpus tests.

@dhruvmanila dhruvmanila merged commit 1685d95 into main Dec 4, 2024
21 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/red-knot-fuzzer branch December 4, 2024 09:07
dcreager added a commit that referenced this pull request Dec 4, 2024
* main:
  [red-knot] Test: Hashable/Sized => A/B (#14769)
  [`flake8-type-checking`] Expands TC006 docs to better explain itself (#14749)
  [`pycodestyle`] Handle f-strings properly for `invalid-escape-sequence (W605)` (#14748)
  [red-knot] Add fuzzer to catch panics for invalid syntax (#14678)
  Check `AIR001` from builtin or providers `operators` module (#14631)
  [airflow]: extend removed names (AIR302) (#14734)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants