Merge commit 'a572185694567dd69a5a752825aca736efe1cb84' into HEAD

This commit is contained in:
FredApps committed 2026-11-11 11:50:27 +01:00
commit 598adddc4f
10 files changed
+101 -37

No files matched your search

+17 -1
View File
@@ -449,7 +449,7 @@ fn windows_unc_root_writes_and_exports_when_supported() {
#[cfg(windows)]
#[test]
fn windows_handle_relative_helpers_match_the_capability_operations() {
let (inside, outside, workspace) = roots("unc-helpers");
let (inside, _outside, workspace) = roots("unc-helpers");
let root = workspace.write.as_ref().unwrap();
assert!(!is_unc_root(root));
@@ -464,7 +464,15 @@ fn windows_handle_relative_helpers_match_the_capability_operations() {
std::fs::create_dir(inside.join("dir")).unwrap();
assert!(delete_on_close(&root.dir, Path::new("dir")).is_err());
assert!(inside.join("dir").is_dir());
}
/// The ambient rename that stands in for the capability's below a UNC root (#10317).
#[cfg(windows)]
#[test]
fn windows_rename_unc_matches_the_capability_rename() {
let (inside, outside, workspace) = roots("unc-rename");
let root = workspace.write.as_ref().unwrap();
std::fs::create_dir(inside.join("dir")).unwrap();
// The ambient rename on the canonical root path behaves like the capability's: it creates,
// replaces a file, replaces a link instead of writing through it, and refuses a directory.
std::fs::write(inside.join("plain.tmp"), b"the longer first version").unwrap();
@@ -487,7 +495,15 @@ fn windows_handle_relative_helpers_match_the_capability_operations() {
assert_eq!(std::fs::read(outside.join("target.png")).unwrap(), b"outside");
}
let _ = std::fs::remove_file(inside.join("plain.tmp"));
}
/// The directory walk that stands in for the capability's `create_dir_all` below a UNC root
/// (#10317) creates, refuses files on the way and never follows a junction outside.
#[cfg(windows)]
#[test]
fn windows_create_dir_all_unc_matches_the_capability_operation() {
let (inside, outside, workspace) = roots("unc-dirs");
let root = workspace.write.as_ref().unwrap();
create_dir_all_unc(root, Path::new("a/b/c")).unwrap();
assert!(inside.join("a/b/c").is_dir());
create_dir_all_unc(root, Path::new("a/b/c")).unwrap();
+29 -25
View File
@@ -775,23 +775,42 @@ fn prepared_warnings(p: &Prepared) -> Vec<DecodeWarning> {
warnings
}
/// Checks one directory and lays it out for decoding. `whole`: the image is decoded into one
/// buffer, which `limits.max_alloc` bounds; otherwise only its size is checked here. Chunk
/// tables larger than `limits.max_alloc` are refused before the `tiff` crate reads them.
fn prepare(f: &File<'_>, dir: &Ifd, limits: &Limits, whole: bool) -> Result<Prepared, CodecError> {
// The values the `tiff` crate reads must exist: a count past the end of the file is
// neither allocated nor read.
/// The structural tags the `tiff` crate reads must exist (a count past the end of the file is
/// neither allocated nor read) and appear once: this parser reads the first entry of a tag and
/// the `tiff` crate the last, so a repeated structural tag (a small SamplesPerPixel first, a
/// large one last) would be checked here with one value and sized by the crate with another.
fn check_structural_tags(f: &File<'_>, dir: &Ifd) -> Result<(), CodecError> {
if let Some(e) = dir.entries.iter().find(|e| ifd::STRUCTURAL_TAGS.contains(&e.tag) && f.data(e).is_none()) {
return Err(err(format!("tag {} points past the end of the file", e.tag)));
}
// This parser reads the first entry of a tag and the `tiff` crate the last, so a repeated
// structural tag (a small SamplesPerPixel first, a large one last) would be checked here with
// one value and sized by the crate with another.
let mut structural: Vec<u16> = dir.entries.iter().map(|e| e.tag).filter(|t| ifd::STRUCTURAL_TAGS.contains(t)).collect();
structural.sort_unstable();
if let Some(w) = structural.windows(2).find(|w| w[0] == w[1]) {
return Err(err(format!("tag {} appears more than once", w[0])));
}
Ok(())
}
/// The bytes the first `expected` strips or tiles hold inside the file, never more than the file.
fn held_bytes(f: &File<'_>, (offsets, sizes): (&ifd::Entry, &ifd::Entry), expected: u64) -> u64 {
let len = f.b.len() as u64;
let mut held = 0u64;
for i in 0..expected {
if held >= len {
break;
}
if let (Some(at), Some(n)) = (f.uint(offsets, i), f.uint(sizes, i)) {
held = held.saturating_add(n.min(len.saturating_sub(at)));
}
}
held.min(len)
}
/// Checks one directory and lays it out for decoding. `whole`: the image is decoded into one
/// buffer, which `limits.max_alloc` bounds; otherwise only its size is checked here. Chunk
/// tables larger than `limits.max_alloc` are refused before the `tiff` crate reads them.
fn prepare(f: &File<'_>, dir: &Ifd, limits: &Limits, whole: bool) -> Result<Prepared, CodecError> {
check_structural_tags(f, dir)?;
let need = |tag: u16, name: &str| f.tag_uint(dir, tag).ok_or_else(|| err(format!("missing or unreadable {name}")));
let w = u32::try_from(need(ifd::TAG_WIDTH, "ImageWidth")?).map_err(|_| err("ImageWidth out of range"))?;
let h = u32::try_from(need(ifd::TAG_HEIGHT, "ImageLength")?).map_err(|_| err("ImageLength out of range"))?;
@@ -934,21 +953,11 @@ fn prepare(f: &File<'_>, dir: &Ifd, limits: &Limits, whole: bool) -> Result<Prep
4 => cw.clamp(4096, 65_535),
_ => 4096,
};
let len = f.b.len() as u64;
let (offsets, sizes) = (
dir.get(offsets_tag).ok_or_else(|| err("missing strip or tile offsets"))?,
dir.get(counts_tag).ok_or_else(|| err("missing strip or tile byte counts"))?,
);
let mut held = 0u64;
for i in 0..expected {
if held >= len {
break;
}
if let (Some(at), Some(n)) = (f.uint(offsets, i), f.uint(sizes, i)) {
held = held.saturating_add(n.min(len.saturating_sub(at)));
}
}
let held = held.min(len);
let held = held_bytes(f, (offsets, sizes), expected);
if stored > held.saturating_mul(ratio).saturating_add(1 << 20) {
return Err(err(format!("the strips or tiles in this file hold {held} bytes, too few for a {w}x{h} image")));
}
@@ -1074,11 +1083,6 @@ fn prepare(f: &File<'_>, dir: &Ifd, limits: &Limits, whole: bool) -> Result<Prep
})
}
/// The JPEGTables tag: quantization and Huffman tables shared by every JPEG strip or tile.
const TAG_JPEG_TABLES: u16 = 347;
/// The Predictor tag (1 none, 2 horizontal differencing, 3 floating point).
const TAG_PREDICTOR: u16 = 317;
/// Steps [`jpeg_sof`] may take per strip or tile beyond the file's length: room to read again
/// the few header segments of strips or tiles that share one stream (a sparse file pointing its
/// blank tiles at one tile).
-1
View File
@@ -127,7 +127,6 @@ fn export_supported_document(
};
let space = photocraft_compose::cmyk_space(doc);
photocraft_color::convert::with_cmyk_space(space.as_ref(), || ex.emit(&doc.layers, &mut tick));
drop(tick);
ctl.progress(layers_share);
let merged = prepare_merged_planes(doc, &mut ex, opts, ctl, fmt, duotone_inks.is_some(), layers_share);
+10 -1
View File
@@ -448,7 +448,16 @@ fn retained_deep_svg_groups_lower_render_and_drop_on_a_bounded_worker() {
let (preview, _) = svg::import_svg_preview_with_work("retained.svg", source.as_bytes(), u64::MAX).unwrap();
assert_eq!(preview.document.max_group_depth(), 100);
assert!(pixel(&preview.document)[3] > 0.5);
let (w, h, pixels) = svg::rasterize_rgba8(source.as_bytes()).unwrap();
// Whole-drawing rasterisation refuses more than 200 nested layers (#10953) with an
// error, not a crash; a drawing within that limit still renders on this small stack.
let refused = svg::rasterize_rgba8(source.as_bytes()).unwrap_err().to_string();
assert!(refused.contains("layers are nested too deeply"), "{refused}");
let within = format!(
"<svg {NS} width=\"8\" height=\"8\">{}<rect width=\"8\" height=\"8\"/>{}</svg>",
"<g opacity=\"0.99\"><rect width=\"1\" height=\"1\"/>".repeat(150),
"</g>".repeat(150)
);
let (w, h, pixels) = svg::rasterize_rgba8(within.as_bytes()).unwrap();
assert_eq!((w, h), (8, 8));
assert!(pixels[3] > 127);
})
+1 -1
View File
@@ -741,7 +741,7 @@ mod clip_segment_tests {
assert!(!starts.is_empty(), "the view at {left} shows dashes");
for d in starts {
let off = d % (2.0 * DASH);
assert!(off < 0.01 || off > 2.0 * DASH - 0.01, "view at {left}: a dash starts {d} from the corner, off the pattern by {off}");
assert!(!(0.01..=2.0 * DASH - 0.01).contains(&off), "view at {left}: a dash starts {d} from the corner, off the pattern by {off}");
}
}
}
+5 -5
View File
@@ -1921,11 +1921,11 @@ fn painting_a_group_is_refused_at_the_press_with_a_message() {
app.ui.dialogs.clear();
app.ui.tool = tool;
tool_event(&mut app, ToolEvent::Down { x: 10.0, y: 10.0, pressure: 1.0 }, egui::Modifiers::NONE);
// The Brush has its own measured alert, tested in `brush_refusal_alert_tests` (#11898).
let want = if tool == Tool::Brush {
"Could not use the brush tool because the pixels in a group cannot be edited without merging the group.".to_string()
} else {
format!("Could not use the {} because the target layer is a group.", tool.label())
// Brush and Classic gradient use the measured alerts (#11898, #12017).
let want = match tool {
Tool::Brush => "Could not use the brush tool because the pixels in a group cannot be edited without merging the group.".to_string(),
Tool::Gradient => "Could not use the gradient tool because the pixels in a group cannot be edited without merging the group.".to_string(),
_ => format!("Could not use the {} because the target layer is a group.", tool.label()),
};
assert_eq!(errors(&app), [want], "{tool:?}");
assert!(app.drag.is_none() && app.live_stroke.is_none(), "{tool:?} starts no stroke");
+1 -1
View File
@@ -92,7 +92,7 @@ pub fn rasterize(variant: PenVariant, scale: f32) -> Option<CustomCursorImage> {
return None;
}
let icon_px_f = (LOGICAL_SIZE * scale).round();
if icon_px_f < 1.0 || icon_px_f > 512.0 {
if !(1.0..=512.0).contains(&icon_px_f) {
return None;
}
let icon_px = icon_px_f as u32;
+9 -1
View File
@@ -125,7 +125,15 @@ pub fn pill_tab(ui: &mut Ui, label: &str, selected: bool) -> Response {
/// Small caps section label.
pub fn section_label(ui: &mut Ui, text: &str) {
let t = Tokens::get(ui.ctx());
ui.label(egui::RichText::new(tl!(text)).font(theme::medium(11.5)).color(t.text_faint));
let text = tl!(text);
let font = theme::medium(11.5);
let galley = ui.painter().layout(text.to_owned(), font.clone(), t.text_faint, ui.available_width());
// A glyph can start before its logical advance (the Urdu Stroke heading does). Reserve
// that bearing in the layout instead of clipping the glyph or relaxing dialog bounds.
let left = (galley.rect.left() - galley.mesh_bounds.left()).max(0.0).ceil() as i8;
egui::Frame::NONE.inner_margin(egui::Margin { left, ..Default::default() }).show(ui, |ui| {
ui.label(egui::RichText::new(text).font(font).color(t.text_faint));
});
}
/// Hairline separator.
+28
View File
@@ -196,6 +196,34 @@ fn drawn_texts(out: &egui::FullOutput) -> Vec<(String, egui::Rect, bool)> {
texts
}
/// The Urdu Stroke heading has a negative left glyph bearing with the shipped fonts. Its ink
/// must stay inside the panel at every scale, even though its logical advance starts at zero.
#[test]
fn section_labels_keep_glyph_bearings_inside_the_panel() {
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
for kind in crate::theme::ThemeKind::ALL {
crate::theme::apply(&ctx, kind);
for ppp in [1.0, 1.25, 2.0] {
ctx.set_pixels_per_point(ppp);
for label in ["Stroke", "\u{644}\u{6a9}\u{6cc}\u{631}", "Location"] {
let mut room = egui::Rect::NOTHING;
let mut out = ctx.run_ui(Default::default(), |ui| {
ui.set_max_width(440.0);
room = ui.max_rect();
super::section_label(ui, label);
});
out.textures_delta.clear();
let texts = drawn_texts(&out);
assert_eq!(texts.len(), 1, "{kind:?} @{ppp}x: {label}");
let (_, ink, _) = &texts[0];
assert!(ink.left() >= room.left() - 0.01, "{kind:?} @{ppp}x: {label} ink {ink:?} in {room:?}");
assert!(ink.right() <= room.right() + 0.01, "{kind:?} @{ppp}x: {label} ink {ink:?} in {room:?}");
}
}
}
}
/// #9635: the shared dialog label column is as wide as its widest label, between the English
/// width and a cap, and a label wider than the column elides inside it.
#[test]
@@ -159,7 +159,7 @@ fn apply_menu_ok_requires_a_row_but_not_variable_definitions() {
assert!(h.state().ui.dialogs.is_empty());
assert_eq!(h.state().session.active().unwrap().doc.variables.active, expected);
if explicit {
assert!(h.state().ui.status.contains("no data set at index 0"));
assert!(h.state().ui.status.contains("no data sets in document"));
} else {
assert!(h.state().ui.status.is_empty(), "{}", h.state().ui.status);
}