Skip to content

Commit 3a26619

Browse files
authored
Fix fuzz f64 generation (#813)
* Fix fuzz f64 generation JSON and GraphQL do not allow Nan or Inf float numbers. These are currently being generated by the fuzzer. Fixes #812
1 parent ffd47c6 commit 3a26619

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

crates/apollo-smith/src/input_value.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<'a> DocumentBuilder<'a> {
165165
// Int
166166
0 => InputValue::Int(self.u.arbitrary()?),
167167
// Float
168-
1 => InputValue::Float(self.u.arbitrary()?),
168+
1 => InputValue::Float(self.finite_f64()?),
169169
// String
170170
2 => InputValue::String(self.limited_string(40)?),
171171
// Boolean
@@ -211,7 +211,7 @@ impl<'a> DocumentBuilder<'a> {
211211
match ty.name().name.as_str() {
212212
"String" => Ok(InputValue::String(doc_builder.limited_string(1000)?)),
213213
"Int" => Ok(InputValue::Int(doc_builder.u.arbitrary()?)),
214-
"Float" => Ok(InputValue::Float(doc_builder.u.arbitrary()?)),
214+
"Float" => Ok(InputValue::Float(doc_builder.finite_f64()?)),
215215
"Boolean" => Ok(InputValue::Boolean(doc_builder.u.arbitrary()?)),
216216
"ID" => Ok(InputValue::Int(doc_builder.u.arbitrary()?)),
217217
other => {
@@ -329,6 +329,15 @@ impl<'a> DocumentBuilder<'a> {
329329
directives,
330330
})
331331
}
332+
333+
fn finite_f64(&mut self) -> arbitrary::Result<f64> {
334+
loop {
335+
let val: f64 = self.u.arbitrary()?;
336+
if val.is_finite() {
337+
return Ok(val);
338+
}
339+
}
340+
}
332341
}
333342

334343
#[cfg(test)]

0 commit comments

Comments
 (0)