Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(tools): cover a bomb-shaped image header and DNS-refusal shapes

oxoxDevcaa2fddc9c9d
diff --git a/src/openhuman/tools/impl/browser/image_info_tests.rs b/src/openhuman/tools/impl/browser/image_info_tests.rs
index 226fb0f228..6f9577c58c 100644
--- a/src/openhuman/tools/impl/browser/image_info_tests.rs
+++ b/src/openhuman/tools/impl/browser/image_info_tests.rs
@@ -236,6 +236,43 @@ async fn execute_real_file() {
let _ = tokio::fs::remove_dir_all(&dir).await;
}
+/// A decompression-bomb-shaped PNG (a header claiming an enormous canvas,
+/// backed by a file well under `MAX_IMAGE_BYTES`) must not blow up memory or
+/// hang: `extract_dimensions` reads four fixed IHDR bytes and never inflates
+/// pixel data, so the claimed 60000x60000 canvas is read as fast as any other
+/// header and no allocation is proportional to it.
+#[tokio::test]
+async fn execute_reports_a_bomb_shaped_header_without_decoding_pixels() {
+ let dir = std::env::temp_dir().join("openhuman_image_info_bomb");
+ let _ = tokio::fs::create_dir_all(&dir).await;
+ let png_path = dir.join("bomb.png");
+
+ let mut bytes = vec![
+ 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, // signature
+ 0x00, 0x00, 0x00, 0x0D, // IHDR length
+ 0x49, 0x48, 0x44, 0x52, // "IHDR"
+ 0x00, 0x00, 0xEA, 0x60, // width: 60000
+ 0x00, 0x00, 0xEA, 0x60, // height: 60000
+ ];
+ bytes.extend_from_slice(&[0u8; 10]); // pad past the 24 bytes IHDR parsing reads
+ tokio::fs::write(&png_path, &bytes).await.unwrap();
+
+ let tool = ImageInfoTool::new(test_security());
+ let start = std::time::Instant::now();
+ let result = tool
+ .execute(json!({"path": png_path.to_string_lossy()}))
+ .await
+ .unwrap();
+ assert!(
+ start.elapsed() < std::time::Duration::from_secs(2),
+ "a 34-byte file must resolve immediately regardless of claimed dimensions"
+ );
+ assert!(!result.is_error, "{}", result.output());
+ assert!(result.output().contains("Dimensions: 60000x60000"));
+
+ let _ = tokio::fs::remove_dir_all(&dir).await;
+}
+
#[tokio::test]
async fn execute_with_base64() {
let dir = std::env::temp_dir().join("openhuman_image_info_b64");
diff --git a/src/openhuman/tools/impl/network/url_guard_tests.rs b/src/openhuman/tools/impl/network/url_guard_tests.rs
index aff5b4ea98..0c6742bbfa 100644
--- a/src/openhuman/tools/impl/network/url_guard_tests.rs
+++ b/src/openhuman/tools/impl/network/url_guard_tests.rs
@@ -182,6 +182,36 @@ async fn dns_check_with_empty_allowlist_blocks_private_resolved_ip() {
assert!(err.contains("DNS rebinding blocked"));
}
+#[tokio::test]
+async fn dns_check_resolver_failure_is_a_refusal_not_a_pass_through() {
+ // A resolver error (NXDOMAIN, network down, timeout) must refuse the
+ // fetch, not fall back to treating the host as unresolved-and-therefore-
+ // allowed.
+ let err = validate_url_with_dns_check_with_resolver(
+ "https://this-host-does-not-exist.invalid",
+ &[],
+ |host, _port| async move { anyhow::bail!("DNS resolution failed for '{host}': NXDOMAIN") },
+ )
+ .await
+ .unwrap_err()
+ .to_string();
+ assert!(err.contains("DNS resolution failed"));
+}
+
+#[tokio::test]
+async fn dns_check_resolver_returning_no_addresses_is_a_refusal() {
+ // A resolver that answers with zero addresses (some stub resolvers do
+ // this instead of erroring) must not be treated as "no IPs to check,
+ // therefore allowed".
+ let err = validate_url_with_dns_check_with_resolver("https://example.com", &[], |_, _| async {
+ Ok(Vec::new())
+ })
+ .await
+ .unwrap_err()
+ .to_string();
+ assert!(err.contains("DNS resolution returned no addresses"));
+}
+
#[test]
fn validate_rejects_ftp_scheme() {
let allow = vec!["example.com".to_string()];