Add GIF unsupported format test (#2618)

This commit is contained in:
Max Novich
2025-05-21 10:31:18 -07:00
committed by GitHub
parent 302ac81990
commit 8fade6b320
2 changed files with 19 additions and 0 deletions

View File

@@ -172,6 +172,8 @@ fn is_image_file(path: &Path) -> bool {
[0x89, 0x50, 0x4E, 0x47] => true,
// JPEG: FF D8 FF
[0xFF, 0xD8, 0xFF, _] => true,
// GIF: 47 49 46 38
[0x47, 0x49, 0x46, 0x38] => true,
_ => false,
};
}

View File

@@ -214,6 +214,8 @@ fn is_image_file(path: &Path) -> bool {
[0x89, 0x50, 0x4E, 0x47] => true,
// JPEG: FF D8 FF
[0xFF, 0xD8, 0xFF, _] => true,
// GIF: 47 49 46 38
[0x47, 0x49, 0x46, 0x38] => true,
_ => false,
};
}
@@ -411,6 +413,21 @@ mod tests {
// Test non-existent file
let result = load_image_file("nonexistent.png");
assert!(result.is_err());
// Create a GIF file with valid header bytes
let gif_path = temp_dir.path().join("test.gif");
// Minimal GIF89a header
let gif_data = [0x47, 0x49, 0x46, 0x38, 0x39, 0x61];
std::fs::write(&gif_path, &gif_data).unwrap();
let gif_path_str = gif_path.to_str().unwrap();
// Test loading unsupported GIF format
let result = load_image_file(gif_path_str);
assert!(result.is_err());
assert!(result
.unwrap_err()
.to_string()
.contains("Unsupported image format"));
}
#[test]