Skip to content
This repository was archived by the owner on May 5, 2023. It is now read-only.

Commit 8937329

Browse files
I forgot [nan] != [nan]
1 parent f3f6d6b commit 8937329

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

fuzz/differential_fuzzer.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
from msgpack import _cmsgpack, fallback
55

66

7+
def replace_nan(data, sentinel):
8+
if type(data) == float and math.isnan(data):
9+
return sentinel
10+
if type(data) == list:
11+
return [replace_nan(x, sentinel) for x in data]
12+
if type(data) == dict:
13+
return {k: replace_nan(v, sentinel) for k, v in data.items()}
14+
return data
15+
16+
717
def TestOneInput(data):
818
try:
919
from_extension = _cmsgpack.unpackb(data)
@@ -13,10 +23,8 @@ def TestOneInput(data):
1323
from_fallback = fallback.unpackb(data)
1424
except:
1525
return
16-
good = from_extension == from_fallback or (
17-
math.isnan(from_extension) and math.isnan(from_fallback)
18-
)
19-
if not good:
26+
sentinel = object()
27+
if replace_nan(from_extension, sentinel) != replace_nan(from_fallback, sentinel):
2028
raise RuntimeError(
2129
f"Decoding disagreement: input: {data}, from extension: {from_extension}, from fallback: {from_fallback}"
2230
)

0 commit comments

Comments
 (0)