Never crash: media crate without expect()
The smart-object branch of the layered-file decoder bound the footage layer twice and
re-read it with expect("embedded implies a layer"); bind it once with a let-chain. Denies the
panic lints in the crate.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
10644a83aa
commit
37c9b449c6
@@ -0,0 +1,4 @@
|
|||||||
|
allow-unwrap-in-tests = true
|
||||||
|
allow-expect-in-tests = true
|
||||||
|
allow-panic-in-tests = true
|
||||||
|
allow-indexing-slicing-in-tests = true
|
||||||
@@ -73,7 +73,9 @@ pub(crate) fn decode(path: &str, bytes: &[u8], footage: &Footage, op: AlphaOp) -
|
|||||||
if effectcraft_psd::is_psd(bytes) {
|
if effectcraft_psd::is_psd(bytes) {
|
||||||
let psd = effectcraft_psd::Psd::parse(bytes.to_vec()).map_err(|e| MediaError::Decode(format!("{path}: {e}")))?;
|
let psd = effectcraft_psd::Psd::parse(bytes.to_vec()).map_err(|e| MediaError::Decode(format!("{path}: {e}")))?;
|
||||||
// A smart object's embedded file: an embedded document's merged image, or an image.
|
// A smart object's embedded file: an embedded document's merged image, or an image.
|
||||||
if let Some(uuid) = footage.layer.as_ref().and_then(|l| l.embedded.as_deref()) {
|
if let Some(l) = footage.layer.as_ref()
|
||||||
|
&& let Some(uuid) = l.embedded.as_deref()
|
||||||
|
{
|
||||||
let data = psd.linked_data(uuid).ok_or_else(|| MediaError::Decode(format!("{path}: no embedded file {uuid}")))?;
|
let data = psd.linked_data(uuid).ok_or_else(|| MediaError::Decode(format!("{path}: no embedded file {uuid}")))?;
|
||||||
let px = if effectcraft_psd::is_psd(data) {
|
let px = if effectcraft_psd::is_psd(data) {
|
||||||
let inner = effectcraft_psd::Psd::parse(data.to_vec()).map_err(|e| MediaError::Decode(format!("{path} (smart object): {e}")))?;
|
let inner = effectcraft_psd::Psd::parse(data.to_vec()).map_err(|e| MediaError::Decode(format!("{path} (smart object): {e}")))?;
|
||||||
@@ -84,7 +86,6 @@ pub(crate) fn decode(path: &str, bytes: &[u8], footage: &Footage, op: AlphaOp) -
|
|||||||
effectcraft_psd::Pixels { width: rgba.width(), height: rgba.height(), data: rgba.pixels().map(|p| p.0).collect() }
|
effectcraft_psd::Pixels { width: rgba.width(), height: rgba.height(), data: rgba.pixels().map(|p| p.0).collect() }
|
||||||
};
|
};
|
||||||
// A perspective quad or a warp: baked as placed.
|
// A perspective quad or a warp: baked as placed.
|
||||||
let l = footage.layer.as_ref().expect("embedded implies a layer");
|
|
||||||
if l.placed
|
if l.placed
|
||||||
&& let Some(so) = psd.layers.get(l.index as usize).and_then(|pl| pl.smart_object.as_ref())
|
&& let Some(so) = psd.layers.get(l.index as usize).and_then(|pl| pl.smart_object.as_ref())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
//! (PNG, JPEG, GIF, WebP, TIFF, BMP, OpenEXR); Photoshop documents (merged image or one layer) come
|
//! (PNG, JPEG, GIF, WebP, TIFF, BMP, OpenEXR); Photoshop documents (merged image or one layer) come
|
||||||
//! from `effectcraft-psd` and SVG from `effectcraft-svg` (rasterised at any scale).
|
//! from `effectcraft-psd` and SVG from `effectcraft-svg` (rasterised at any scale).
|
||||||
|
|
||||||
|
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
|
||||||
|
|
||||||
mod convert;
|
mod convert;
|
||||||
pub mod exr_channels;
|
pub mod exr_channels;
|
||||||
mod layered;
|
mod layered;
|
||||||
|
|||||||
Reference in New Issue
Block a user