Skip to content

Commit 327df99

Browse files
committed
Handle invalid non-ASCII struct formats in the fuzz harness
1 parent fce11ab commit 327df99

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

‎Lib/test/test_xxtestfuzz.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def test_sample_input_smoke_test(self):
1818
_xxtestfuzz.run(b"1")
1919
_xxtestfuzz.run(b"AAAAAAA")
2020
_xxtestfuzz.run(b"AAAAAA\0")
21+
_xxtestfuzz.run(b"\xff\0")
2122

2223

2324
if __name__ == "__main__":

‎Modules/_xxtestfuzz/fuzzer.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ static int fuzz_struct_unpack(const char* data, size_t size) {
133133
if (unpacked == NULL && PyErr_ExceptionMatches(PyExc_SystemError)) {
134134
PyErr_Clear();
135135
}
136+
/* Ignore any ValueError, these are triggered by non-ASCII format. */
137+
if (unpacked == NULL && PyErr_ExceptionMatches(PyExc_ValueError)) {
138+
PyErr_Clear();
139+
}
136140
/* Ignore any struct.error exceptions, these can be caused by invalid
137141
formats or incomplete buffers both of which are common. */
138142
if (unpacked == NULL && PyErr_ExceptionMatches(struct_error)) {

0 commit comments

Comments
 (0)