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

test: add fuzz testing #18

Merged
merged 4 commits into from
Oct 13, 2023
Merged

test: add fuzz testing #18

merged 4 commits into from
Oct 13, 2023

Conversation

sheerlox
Copy link
Owner

@sheerlox sheerlox commented Oct 13, 2023

Though process

First tried to implement a "real" fuzzing test with @jazzer.js/core and @jazzer.js/jest-runner (see Notes).
Things were not working out as expected, so I came up with a working solution (see Solution).

Notes

  • Jazzer.js cannot instrument ES modules correctly, so it needs to integrate with Jest
  • we need to run Jest in watch mode, or else every line of fuzz output is eaten by Jest's status
  • there seems to be a memory issue in the Jest integration of Jazzer.js. RSS was stable when running with its standalone version, but when using Jest it keeps stacking until it reaches OOM
  • the Jest integration is running way more slowly than the standalone version
  • the corpus for the Jest test is located in .cifuzz-corpus/fuzz.test/importFrom/, and crashes are located in tests/fuzzing/fuzz.test/importFrom/
  • using the new FuzzedDataProvider(buffer).consumeString() method seems more performant than buffer.toString() (~15%) (in the standalone version, in Jest it's the opposite)

Solution

Based on the above observations (difficulty, if not impossibility, to implement fuzzing libraries for ESM packages) and choices made by ossf/scorecard, the "fuzzing" process is using the fast-check library (or more specifically its @fast-check/ava test runner integration).

Side notes

While working on this issue, I noticed ossf/scorecard didn't detect fast-check test runners integrations correctly, so I've opened issue ossf/scorecard#3567 and submitted PR ossf/scorecard#3568 to fix that.

In the meantime, I've added a "hack" import so fast-check gets detected correctly by ossf/scorecard.

@sheerlox sheerlox self-assigned this Oct 13, 2023
@sheerlox sheerlox changed the title test: add fuzzing test test: add fuzz testing Oct 13, 2023
@sheerlox sheerlox merged commit 9abddb5 into main Oct 13, 2023
9 checks passed
@sheerlox sheerlox deleted the test/fuzzing branch October 13, 2023 14:16
sheerlox pushed a commit that referenced this pull request Oct 21, 2023
## [1.0.2](v1.0.1...v1.0.2) (2023-10-21)

### 🛠 Builds

* configure and run knip ([0f38051](0f38051))

### 📚 Documentation

* add PURPOSE.md ([13e24f9](13e24f9))

### 🚨 Tests

* add fuzz testing ([#18](#18)) ([9abddb5](9abddb5))

### ⚙️ Continuous Integrations

* **action:** enable ossf scorecard repo_token ([390edd7](390edd7))
* **action:** update actions/checkout action to v4.1.1 ([#23](#23)) ([fcdb52c](fcdb52c))
* **action:** update actions/checkout digest to b4ffde6 ([#24](#24)) ([93c99ed](93c99ed))
* **action:** update github/codeql-action action to v2.22.2 ([#17](#17)) ([7d49e7f](7d49e7f)), closes [#9](#9)
* **action:** update github/codeql-action action to v2.22.3 ([#20](#20)) ([3611086](3611086)), closes [#9](#9)
* **action:** update github/codeql-action action to v2.22.3 ([#21](#21)) ([45faedc](45faedc))
* **action:** update github/codeql-action action to v2.22.4 ([#25](#25)) ([fe13382](fe13382))

### ♻️ Chores

* **deps:** lock file maintenance ([#22](#22)) ([8d686b1](8d686b1))
* **deps:** pin dependency [@fast-check](https://github.com/fast-check)/ava to 1.1.6 ([#19](#19)) ([a82bbb2](a82bbb2))
* remove ossf scorecard fast-check detection hack ([ca95e03](ca95e03))
@sheerlox
Copy link
Owner Author

🎉 This PR is included in version 1.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant