Skip to content

Commit

Permalink
Add tests to ensure EC bin parsing fails gracefully
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Schaefer <dhs@frame.work>
  • Loading branch information
JohnAZoidberg committed May 12, 2024
1 parent fdf982c commit 09ea9a1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions framework_lib/src/ec_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,26 @@ mod tests {
assert_eq!(expected, read_ec_version(&data, false));
assert_eq!(expected, read_ec_version(&data, true));
}

#[test]
// Make sure it doesn't crash when reading an invalid binary
// Cargo.toml is significantly smaller than ec.bin
fn fails_cargo_toml() {
let mut ec_bin_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
ec_bin_path.push("Cargo.toml");
let data = fs::read(ec_bin_path).unwrap();
assert_eq!(None, read_ec_version(&data, false));
assert_eq!(None, read_ec_version(&data, true));
}

#[test]
// Make sure it doesn't crash when reading an invalid binary
// winux.bin is slightly larger than ec.bin
fn fails_winux() {
let mut ec_bin_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
ec_bin_path.push("test_bins/winux.bin");
let data = fs::read(ec_bin_path).unwrap();
assert_eq!(None, read_ec_version(&data, false));
assert_eq!(None, read_ec_version(&data, true));
}
}

0 comments on commit 09ea9a1

Please sign in to comment.