From 76cd8a017c24b104ca681ad0ec9ca345db25b2bf Mon Sep 17 00:00:00 2001 From: Daniel Hofbauer Date: Mon, 9 Nov 2026 23:16:13 +0100 Subject: [PATCH 1/2] fix(ui): the identify pop-up's picture formats don't depend on the build's decoders popupmedia::decode said a format was unsupported only when the image crate had no decoder for it, and arboard (the clipboard) adds BMP on Windows and TIFF on macOS. The same file got a different answer per platform, and decoding_keeps_the_caps failed there. It now checks the format against a fixed list (PNG, JPEG, WebP, GIF). Closes #1697 --- crates/ui-egui/src/popupmedia.rs | 31 ++++++++++++++++++++----------- docs/user-guide/editing.md | 5 +++-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/crates/ui-egui/src/popupmedia.rs b/crates/ui-egui/src/popupmedia.rs index 8257621c82..2309321e62 100644 --- a/crates/ui-egui/src/popupmedia.rs +++ b/crates/ui-egui/src/popupmedia.rs @@ -327,19 +327,24 @@ fn header(bytes: &[u8]) -> Result>, Fa Ok(reader) } -/// Decodes a fetched picture for the pop-up: refused when it isn't one, or when its header says -/// it is larger than [`crate::mapview::decode_picture`] takes (before anything is decoded, so a -/// small file can't unpack into a huge picture), and kept at most [`MAX_SIDE`] pixels a side. +/// The picture formats the pop-up shows. A fixed list, not whatever decoders `image` happens to be +/// built with: another crate in the build can add one (`arboard`, through the clipboard, adds BMP +/// on Windows and TIFF on macOS), and the same file must give the same answer on every platform. +const SHOWN: [image::ImageFormat; 4] = + [image::ImageFormat::Png, image::ImageFormat::Jpeg, image::ImageFormat::WebP, image::ImageFormat::Gif]; + +/// Decodes a fetched picture for the pop-up: refused when it isn't one, or is in a format outside +/// [`SHOWN`], or when its header says it is larger than [`crate::mapview::decode_picture`] takes +/// (before anything is decoded, so a small file can't unpack into a huge picture), and kept at +/// most [`MAX_SIDE`] pixels a side. pub(crate) fn decode(bytes: &[u8]) -> Result { let header = header(bytes)?; let Some(format) = header.format() else { return Err(Failure::NotPicture) }; - // A picture whose format has no decoder here says so, rather than that it isn't one. - let (w, h) = header.into_dimensions().map_err(|e| match e { - image::ImageError::Unsupported(u) if matches!(u.kind(), image::error::UnsupportedErrorKind::Format(_)) => { - Failure::Unsupported(format!("{format:?}").to_uppercase()) - } - _ => Failure::NotPicture, - })?; + // A picture in another format says so, rather than that it isn't one. + if !SHOWN.contains(&format) { + return Err(Failure::Unsupported(format!("{format:?}").to_uppercase())); + } + let (w, h) = header.into_dimensions().map_err(|_| Failure::NotPicture)?; if w > MAX_DECODED_SIDE || h > MAX_DECODED_SIDE { return Err(Failure::TooLarge(w, h)); } @@ -548,13 +553,17 @@ mod tests { assert_eq!(Failure::TooLarge(4000, 3000).line(), "Picture unavailable: 4000 × 3000 pixels is larger than 2048 × 2048"); assert_eq!(decode(b"Not found"), Err(Failure::NotPicture)); assert_eq!(decode(&[]), Err(Failure::NotPicture)); - // A picture whose format isn't read here says so, not that it isn't a picture. + // A picture in a format the pop-up doesn't show says so, not that it isn't a picture, whatever + // decoders the build has (the clipboard adds BMP on Windows and TIFF on macOS). let mut bmp = b"BM".to_vec(); bmp.resize(64, 0); assert_eq!(decode(&bmp), Err(Failure::Unsupported("BMP".into()))); let mut tiff = b"II*\0".to_vec(); tiff.resize(64, 0); assert_eq!(decode(&tiff), Err(Failure::Unsupported("TIFF".into()))); + // A GIF is shown (a 1 × 1 one). + let gif = b"GIF89a\x01\0\x01\0\x80\0\0\0\0\0\xff\xff\xff!\xf9\x04\x01\0\0\0\0,\0\0\0\0\x01\0\x01\0\0\x02\x02D\x01\0;"; + assert_eq!(decode(gif).unwrap().dimensions(), (1, 1)); assert_eq!(Failure::Unsupported("BMP".into()).line(), "Picture unavailable: BMP pictures aren't supported"); // A picture cut short doesn't decode. let whole = png(64, 64); diff --git a/docs/user-guide/editing.md b/docs/user-guide/editing.md index cf8cd6e956..aea9698b5c 100644 --- a/docs/user-guide/editing.md +++ b/docs/user-guide/editing.md @@ -226,8 +226,9 @@ such as `image_page_url` or `image_credit` stay links or text in the list. A picture from RustGIS's own asset server (`https://assets.rustgis.app/…`) is fetched as the pop-up opens. A picture from any other server isn't: the pop-up shows **Show Picture** and the server's name, and fetches nothing until you click it, because the request tells that server that someone -opened the data (see [Privacy](../privacy.md)). A spinner shows while a picture is fetched. Pictures -of up to 4 MB and 2048 × 2048 pixels are shown; the last 16 addresses' pictures are kept for the +opened the data (see [Privacy](../privacy.md)). A spinner shows while a picture is fetched. PNG, JPEG, +WebP and GIF pictures of up to 4 MB and 2048 × 2048 pixels are shown (on every platform; any other +format, such as BMP or TIFF, is "not supported"); the last 16 addresses' pictures are kept for the session, so opening the pop-up again shows the picture without asking again; they are forgotten with the web layers' cached tiles (signing out of ArcGIS, a login that ends, **Reload Web Layers**). When one can't be shown, the pop-up says why ("Picture unavailable: …": the server's answer, a network From 510eba7a4ac9ecacd7d5844953b2dde999cc1b58 Mon Sep 17 00:00:00 2001 From: Daniel Hofbauer Date: Mon, 9 Nov 2026 23:26:19 +0100 Subject: [PATCH 2/2] fix(ui): ui-egui declares the image gif feature the pop-up's format list needs --- crates/ui-egui/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-egui/Cargo.toml b/crates/ui-egui/Cargo.toml index 942d37deb0..48f1f17c99 100644 --- a/crates/ui-egui/Cargo.toml +++ b/crates/ui-egui/Cargo.toml @@ -29,7 +29,7 @@ unicode-normalization = "0.1" sys-locale = { version = "0.3", features = ["js"] } # Pictures kept with features (photo thumbnails), shown in the identify popup. -image = { workspace = true, features = ["jpeg", "webp"] } +image = { workspace = true, features = ["gif", "jpeg", "webp"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] rfd = { workspace = true }