fix: tighten edge cases across services (#3158)

This commit is contained in:
Hampus authored and GitHub committed 2026-10-03 13:04:29 +02:00
1 parent a9f7a23c0d
commit 4e6b837ccc
170 files changed
+2028 -421

No files matched your search

+2 -2
View File
@@ -416,7 +416,7 @@ pub(super) fn encode_animated_apng(
page_height: c_int,
limits: AnimLimits,
media_limits: &MediaLimits,
carried_loop_count: Option<u32>,
source_loop_count: Option<u32>,
) -> Result<Vec<u8>, MediaError> {
let width = unsafe { native::fluxer_vips_image_get_width(image.as_ptr()) };
let total_height = unsafe { native::fluxer_vips_image_get_height(image.as_ptr()) };
@@ -451,7 +451,7 @@ pub(super) fn encode_animated_apng(
if frame_count == 0 {
return Err(MediaError::MediaEncodeFailed);
}
let num_plays = resolve_animation_loop_count(image, carried_loop_count);
let num_plays = resolve_animation_loop_count(image, source_loop_count);
let expected_width = width as u32;
let expected_height = page_height as u32;
@@ -183,9 +183,9 @@ pub(super) fn encode_vips_image(
pub(super) fn resolve_animation_loop_count(
image: &VipsImageHandle<'_>,
carried: Option<u32>,
source_loop_count: Option<u32>,
) -> u32 {
if let Some(loop_count) = carried {
if let Some(loop_count) = source_loop_count {
return loop_count;
}
let field = c"loop";
@@ -135,7 +135,7 @@ fn patch_apng_num_plays(bytes: &[u8], num_plays: u32) -> Vec<u8> {
let position = out
.windows(4)
.position(|window| window == b"acTL")
.expect("fixture carries an acTL chunk");
.expect("fixture has an acTL chunk");
let payload_start = position + 4;
out[payload_start + 4..payload_start + 8].copy_from_slice(&num_plays.to_be_bytes());
let payload: [u8; 8] = out[payload_start..payload_start + 8]
@@ -147,7 +147,7 @@ fn patch_apng_num_plays(bytes: &[u8], num_plays: u32) -> Vec<u8> {
}
#[test]
fn animated_apng_transform_carries_the_source_num_plays() {
fn animated_apng_transform_keeps_the_source_num_plays() {
let fixture_b64 = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAACXBIWXMAAAABAAAAAQBPJcTWAAAACGFjVEwAAAACAAAAAPONk3AAAAAaZmNUTAAAAAAAAAAQAAAAEAAAAAAAAAAAAAEABQAAaBqIGAAAAK1JREFUeJxjqGf4hxUxIKF/DH+BiOH/fxAiU4Mcgx0aYkBCtgy2QMRgZwdCg1yDCQMvEL1oMACix00mQCTFwANE/gx8QHSrUwuI0DXsbpkCVJ3IwBDEwADUsLprLkTD2ZoeoOp8OQZgaIEQxG5IiNqCXQARQw5pqJOooCFPj+Fcn96x9gxTBpS49NBk2DwlhBoaaOkHZUOGqYvDnrWJt6kRF6xADUAE1ABEuCIOAPEY5L3Pr8FWAAAAGmZjVEwAAAABAAAAAQAAAAEAAAAAAAAAAAABAAUAAMpQnTkAAAAQZmRBVAAAAAJ4nGOoZ/gHAAJ/AX511aUxAAAAAElFTkSuQmCC";
let apng = base64::engine::general_purpose::STANDARD
.decode(fixture_b64)
@@ -71,7 +71,7 @@ fn animated_webp_transforms_directly_and_falls_through_on_embedded_metadata() {
assert_eq!(&direct.bytes[8..12], b"WEBP");
assert!(direct.bytes.windows(4).any(|chunk| chunk == b"ANIM"));
let (canvas_width, canvas_height, feature_flags) =
webp_canvas_size(&direct.bytes).expect("direct output carries a VP8X canvas");
webp_canvas_size(&direct.bytes).expect("direct output has a VP8X canvas");
assert_eq!((16, 16), (canvas_width, canvas_height));
assert_ne!(0, feature_flags & 0x02);
let source_frames = webp_chunk_payloads(&source, b"ANMF").len();
@@ -110,12 +110,12 @@ fn animated_webp_transforms_directly_and_falls_through_on_embedded_metadata() {
}
#[test]
fn animated_webp_encode_carries_the_source_loop_count() {
fn animated_webp_encode_keeps_the_source_loop_count() {
let mut gif = animated_gif_fixture();
let netscape = gif
.windows(11)
.position(|window| window == b"NETSCAPE2.0")
.expect("fixture carries a NETSCAPE application extension");
.expect("fixture has a NETSCAPE application extension");
gif[netscape + 13] = 3;
gif[netscape + 14] = 0;
assert_eq!(Some(3), gif_loop_count(&gif));
@@ -206,10 +206,10 @@ fn hdr_pq_avif_tone_maps_even_when_the_colour_signal_is_one_libheif_cannot_model
let nclx = avif
.windows(8)
.position(|window| window == b"colrnclx")
.expect("fixture carries an nclx colour box");
.expect("fixture has an nclx colour box");
assert!(
avif.windows(8).any(|window| window == b"colrprof"),
"fixture carries an icc colour box"
"fixture has an icc colour box"
);
let mut cases = vec![("an icc profile", avif.clone())];
for (label, offset) in [
@@ -113,7 +113,7 @@ fn metadata_json_treats_mp4_attached_picture_as_audio_cover_art() {
}
#[test]
fn metadata_json_accepts_audio_carrying_png_cover_art() {
fn metadata_json_accepts_audio_with_png_cover_art() {
let mp3 = fixture_audio_mp3_with_png_cover_art();
assert_eq!("audio/mpeg", mime::sniff(&mp3).mime);
let probe = probe_av_metadata(&mp3, NSFW_PREVIEW_MAX_DIMENSION, &test_media_limits(), None)