8000 bpo-29505: Add fuzz tests for float(str), int(str), unicode(str) by ssbr · Pull Request #2878 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-29505: Add fuzz tests for float(str), int(str), unicode(str) #2878

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

Merged
merged 23 commits into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8316e8d
Add basic fuzz tests for a few common builtin functions.
ssbr Jul 21, 2017
f47f875
Remove fuzzing of hash() per comment by kcc / oss-fuzz-team.
ssbr Jul 25, 2017
d112252
Move LLVMFuzzerTestOneInput into cpython and tweak how test discovery…
ssbr Jul 25, 2017
cb9cdc0
Move the fuzzer to C++ so that it builds.
ssbr Jul 25, 2017
7028614
Run the fuzz smoke tests on a little more input, just for kicks.
ssbr Jul 26, 2017
2b34f07
Make the _fuzz module optional.
ssbr Jul 26, 2017
f77be65
Actually run the fuzz tests...
ssbr Jul 26, 2017
778c827
Use unittest.main instead of test.support.
ssbr Jul 26, 2017
bc3d33f
Use C-style comments. (For porting to Python 2.7 and C89).
ssbr Jul 27, 2017
dee024f
Fix build break I accidentally introduced in f77be65.
ssbr Jul 27, 2017
9a00b23
Add a little detail on what the heck this stuff even is, in readme.
ssbr Jul 27, 2017
d542130
s/fuzzer.c/fuzzer.cpp/
ssbr Jul 27, 2017
9f16dd4
fuzzer.cpp -> fuzzer.c in faith that I can make it build.
ssbr Aug 3, 2017
aa6d784
Make _fuzz required, so that tests never fail on a successful build.
ssbr Aug 23, 2017
fa0af73
Fix the windows test failure by just not testing on windows. :)
ssbr Aug 23, 2017
4af5c11
NEWS entry thingermajig.
ssbr Aug 24, 2017
fb017ed
Blacklist test_fuzz from coverage tests. It seems to fail with a Memo…
ssbr Aug 24, 2017
c4eda5d
Remove outdated comment.
ssbr Aug 24, 2017
83967f9
Fix incorrect mod for base (should be % 37), and document why we're t…
ssbr Aug 25, 2017
52dccc2
Use more idiomatic NULL checks rather than PyErr_Occurred().
ssbr Aug 25, 2017
4327fd9
Attempt to explain a little more why these exist / what the relations…
ssbr Aug 25, 2017
6da8e97
Renamed _fuzz to _xxtestfuzz and cleanup.
gpshead Sep 6, 2017
43620ae
don't skip test_fuzz (besides, it was renamed)
gpshead Sep 6, 2017
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
Prev Previous commit
Next Next commit
Run the fuzz smoke tests on a little more input, just for kicks.
(i.e. just to get increased confidence we won't immediately crash on fuzzing.)

I'm using s# because I'd like to minimize the diff between Python 2 and 3.
  • Loading branch information
ssbr committed Jul 26, 2017
commit 7028614379bf37a585c08b153088fc527fddb3fc
9 changes: 7 additions & 2 deletions Lib/test/test_fuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
class TestFuzz(unittest.TestCase):

def test_fuzz(self):
"""Run the fuzz tests on blank input.
"""Run the fuzz tests on sample input.

This isn't meaningful and only checks it doesn't crash.
"""
_fuzz.run()
_fuzz.run(b"")
_fuzz.run(b"\0")
_fuzz.run(b"{")
_fuzz.run(b" ")
_fuzz.run(b"x")
_fuzz.run(b"1")

if __name__ == "__main__":
support.run_unittest(TestFuzz)
Copy link
Member

Choose a reason for hiding this comment

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

Will the usual unittest.main(verbosity=<select>) not work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I cribbed this from an existing test, (I assumed CPython had some weird test framework), but I see I must've picked the wrong test to crib from. :)

Fixed.

11 changes: 8 additions & 3 deletions Modules/_fuzz/_fuzzmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);

static PyObject* _fuzz_run(PyObject* self) {
int rv = LLVMFuzzerTestOneInput((const uint8_t*)"", 0);
static PyObject* _fuzz_run(PyObject* self, PyObject* args) {
const char* buf;
size_t size;
if (!PyArg_ParseTuple(args, "s#", &buf, &size)) {
return NULL;
}
int rv = LLVMFuzzerTestOneInput((const uint8_t*)buf, size);
if (PyErr_Occurred()) {
return NULL;
}
Expand All @@ -19,7 +24,7 @@ static PyObject* _fuzz_run(PyObject* self) {
}

static PyMethodDef module_methods[] = {
{"run", (PyCFunction)_fuzz_run, METH_NOARGS, ""},
{"run", (PyCFunction)_fuzz_run, METH_VARARGS, ""},
{NULL},
};

Expand Down
0