fix(media-proxy): budget native image work by pod memory (#3385)

This commit is contained in:
Hampus authored and GitHub committed 2026-10-11 02:07:19 +02:00
1 parent 575a5adbef
commit 7d2c51a57f
20 files changed
+663 -133

No files matched your search

@@ -1,14 +1,16 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
use super::super::ImageOptions;
use super::super::image_probe::load_image;
use super::super::native_runtime::ensure_vips_init;
use super::super::transform::source_supports_pages;
use super::super::{ImageOptions, MediaError, image_transform_cost};
use super::fixtures::{animated_mode, metadata_value, transform_image};
use crate::{
mime, native,
output_format::OutputFormat,
test_fixtures::{synthetic_bmp, synthetic_png},
test_fixtures::{
JXL_64_LOSSY_ALPHA, JXL_4100_LOSSY_ALPHA, png_dimensions, synthetic_bmp, synthetic_png,
},
};
#[test]
@@ -103,3 +105,105 @@ fn source_supports_pages_matches_libvips_loader_list() {
assert!(!source_supports_pages("image/bmp"));
assert!(!source_supports_pages("application/octet-stream"));
}
#[test]
fn refuses_jxl_above_the_decode_pixel_cap_before_decoding() {
for width in [None, Some(128)] {
let err = transform_image(
JXL_4100_LOSSY_ALPHA,
&ImageOptions {
width,
format: OutputFormat::WebP,
..Default::default()
},
)
.unwrap_err();
assert_eq!(MediaError::InvalidImageDimensions, err);
}
}
#[test]
fn transforms_jxl_within_the_decode_pixel_cap() {
let out = transform_image(
JXL_64_LOSSY_ALPHA,
&ImageOptions {
width: Some(32),
format: OutputFormat::WebP,
..Default::default()
},
)
.unwrap();
assert_eq!("image/webp", out.content_type);
}
#[test]
fn refuses_full_size_svg_raster_above_the_static_output_cap() {
let svg = br#"<svg xmlns="http://www.w3.org/2000/svg" width="16383" height="16383"></svg>"#;
let err = transform_image(
svg,
&ImageOptions {
format: OutputFormat::WebP,
..Default::default()
},
)
.unwrap_err();
assert_eq!(MediaError::InvalidImageDimensions, err);
let err = transform_image(
svg,
&ImageOptions {
width: Some(16384),
format: OutputFormat::WebP,
..Default::default()
},
)
.unwrap_err();
assert_eq!(MediaError::InvalidImageDimensions, err);
}
#[test]
fn rasterizes_large_svg_into_a_bounded_box() {
let svg = br#"<svg xmlns="http://www.w3.org/2000/svg" width="16383" height="16383"></svg>"#;
let out = transform_image(
svg,
&ImageOptions {
width: Some(64),
height: Some(64),
format: OutputFormat::PNG,
..Default::default()
},
)
.unwrap();
assert_eq!(Some((64, 64)), png_dimensions(&out.bytes));
}
#[test]
fn transform_cost_charges_the_full_source_decode_for_jxl() {
let cost = image_transform_cost(
JXL_4100_LOSSY_ALPHA,
&ImageOptions {
width: Some(128),
format: OutputFormat::WebP,
..Default::default()
},
&super::fixtures::test_media_limits(),
)
.unwrap();
assert!(cost >= 4100 * 4100 * 40, "cost {cost}");
}
#[test]
fn transform_cost_charges_svg_at_its_output_size() {
let svg = br#"<svg xmlns="http://www.w3.org/2000/svg" width="16383" height="16383"></svg>"#;
let cost = image_transform_cost(
svg,
&ImageOptions {
width: Some(64),
height: Some(64),
format: OutputFormat::WebP,
..Default::default()
},
&super::fixtures::test_media_limits(),
)
.unwrap();
assert!(cost < 1 << 20, "cost {cost}");
}