mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 22:14:30 +00:00
fix(metadata,raw,svg): address CodeRabbit review findings
This commit is contained in:
+15
-11
@@ -390,18 +390,22 @@ fn trak(bytes: &[u8], t: &BoxRef, budget: &mut usize) -> Option<Cr3Track> {
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
// Missing offset-table counts deny sample access, but the known
|
||||
// Missing or truncated offset-table counts deny sample access, but the known
|
||||
// track must remain available to the largest-raw-track selector.
|
||||
b"co64" => match be32(body, 4) {
|
||||
Some(count) if count > 0 => offset = be64(body, 8).and_then(|v| usize::try_from(v).ok()),
|
||||
None => offset = None,
|
||||
_ => {}
|
||||
},
|
||||
b"stco" => match be32(body, 4) {
|
||||
Some(count) if count > 0 => offset = be32(body, 8).map(|v| v as usize),
|
||||
None => offset = None,
|
||||
_ => {}
|
||||
},
|
||||
b"co64" => {
|
||||
offset = match be32(body, 4) {
|
||||
Some(count) if count > 0 && count as usize <= body.len().saturating_sub(8) / 8 => {
|
||||
be64(body, 8).and_then(|v| usize::try_from(v).ok())
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
}
|
||||
b"stco" => {
|
||||
offset = match be32(body, 4) {
|
||||
Some(count) if count > 0 && count as usize <= body.len().saturating_sub(8) / 4 => be32(body, 8).map(|v| v as usize),
|
||||
_ => None,
|
||||
};
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,9 +99,9 @@ fn measured_red_row(data: &[u16], width: usize, area: Rect, black: f32, white: f
|
||||
}
|
||||
let d = [diff[0] / n[0] as f64, diff[1] / n[1] as f64];
|
||||
let rel = [0, 1].map(|p| (upper[p] - lower[p]).abs() / (upper[p] + lower[p]).max(1.0));
|
||||
if d[0] < 0.8 * d[1] && rel[0] < rel[1] {
|
||||
if d[0] < 0.8 * d[1] && d[1] - d[0] > 4.0 && rel[0] < rel[1] {
|
||||
Some(1)
|
||||
} else if d[1] < 0.8 * d[0] && rel[1] < rel[0] {
|
||||
} else if d[1] < 0.8 * d[0] && d[0] - d[1] > 4.0 && rel[1] < rel[0] {
|
||||
Some(0)
|
||||
} else {
|
||||
None
|
||||
|
||||
@@ -301,7 +301,7 @@ pub(crate) fn decode(bytes: &[u8], mode: Mode, limits: &Limits) -> Result<RawIma
|
||||
// the white level is measured from the whole image (or known for a measured body); the probe (no samples in its
|
||||
// result) takes the nominal one
|
||||
let (white, white_source) = match (body.and_then(|b| b.white), mode) {
|
||||
(Some(white), _) => (white, crate::LevelSource::Inferred),
|
||||
(Some(white), _) => (white, crate::LevelSource::Fallback),
|
||||
(None, Mode::Full) => white_from_data_sourced(samples, bits),
|
||||
(None, Mode::Header) => (((1u32 << bits.clamp(1, 16)) - 1) as f32, crate::LevelSource::Fallback),
|
||||
};
|
||||
|
||||
@@ -480,6 +480,10 @@ fn embedded(used: &Used, limits: &Limits, data: &[u8], options: &usvg::Options<'
|
||||
used.svg_resource_limit.fetch_add(1, Ordering::Relaxed);
|
||||
return None;
|
||||
}
|
||||
Err(Error::TooDeep(_)) => {
|
||||
used.svg_limit.fetch_add(1, Ordering::Relaxed);
|
||||
return None;
|
||||
}
|
||||
Err(_) => {
|
||||
used.invalid_svg.fetch_add(1, Ordering::Relaxed);
|
||||
return None;
|
||||
|
||||
Reference in New Issue
Block a user