From 8fade6b320f0787131aea2946cd3af54700d4984 Mon Sep 17 00:00:00 2001 From: Max Novich Date: Wed, 21 May 2025 10:31:18 -0700 Subject: [PATCH] Add GIF unsupported format test (#2618) --- crates/goose-llm/src/providers/utils.rs | 2 ++ crates/goose/src/providers/utils.rs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/crates/goose-llm/src/providers/utils.rs b/crates/goose-llm/src/providers/utils.rs index 914bad44..caca0a00 100644 --- a/crates/goose-llm/src/providers/utils.rs +++ b/crates/goose-llm/src/providers/utils.rs @@ -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, }; } diff --git a/crates/goose/src/providers/utils.rs b/crates/goose/src/providers/utils.rs index 9697e67b..c73023b4 100644 --- a/crates/goose/src/providers/utils.rs +++ b/crates/goose/src/providers/utils.rs @@ -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]