Skip to content

Commit 31c41a6

Browse files
Fix fuzz_builtin_int fuzzer reproducibility (#145890)
1 parent 0575ce9 commit 31c41a6

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

Modules/_xxtestfuzz/fuzzer.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,18 @@ static int fuzz_builtin_float(const char* data, size_t size) {
3838
static int fuzz_builtin_int(const char* data, size_t size) {
3939
/* Ignore test cases with very long ints to avoid timeouts
4040
int("9" * 1000000) is not a very interesting test caase */
41-
if (size > MAX_INT_TEST_SIZE) {
41+
if (size < 1 || size > MAX_INT_TEST_SIZE) {
4242
return 0;
4343
}
44-
/* Pick a random valid base. (When the fuzzed function takes extra
45-
parameters, it's somewhat normal to hash the input to generate those
46-
parameters. We want to exercise all code paths, so we do so here.) */
47-
int base = Py_HashBuffer(data, size) % 37;
44+
// Use the first byte to pick a base
45+
int base = ((unsigned char) data[0]) % 37;
4846
if (base == 1) {
4947
// 1 is the only number between 0 and 36 that is not a valid base.
5048
base = 0;
5149
}
52-
if (base == -1) {
53-
return 0; // An error occurred, bail early.
54-
}
55-
if (base < 0) {
56-
base = -base;
57-
}
50+
51+
data += 1;
52+
size -= 1;
5853

5954
PyObject* s = PyUnicode_FromStringAndSize(data, size);
6055
if (s == NULL) {

0 commit comments

Comments
 (0)