mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Batch 18 (#11458): a guarded label lookup in the Content-Aware crop donor check
The donor check indexed the label buffer directly; the bounds are inside the canvas today, but a lookup that is out of range now counts as no donor instead of panicking. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
2a6bee9ba3
commit
6e42bc901e
1 file changed
+6
-1
@@ -164,7 +164,12 @@ fn fill_layer(doc: &mut Document, id: Result<LayerId>, cov: &Coverage, own_pixel
|
||||
let donor_bounds = own_pixels.then(|| if has_alpha { surf.content_bounds().intersect(&canvas) } else { canvas });
|
||||
// The added target is optional when it has no covered pixels of its own to sample.
|
||||
// This check does not absorb errors from synthesis or allocation.
|
||||
if donor_bounds.is_some_and(|bounds| !contains_donor(bounds, |x, y| labels[y as usize * w + x as usize] == 0 && has_pixel(x, y))) {
|
||||
if donor_bounds.is_some_and(|bounds| {
|
||||
!contains_donor(bounds, |x, y| {
|
||||
let at = usize::try_from(y).ok().and_then(|y| y.checked_mul(w)).zip(usize::try_from(x).ok()).and_then(|(r, x)| r.checked_add(x));
|
||||
at.and_then(|i| labels.get(i)) == Some(&0) && has_pixel(x, y)
|
||||
})
|
||||
}) {
|
||||
return Ok(false);
|
||||
}
|
||||
let pieces = label_components(&mut labels, w, h)?;
|
||||
|
||||
Reference in new issue
Block a user