Never crash: PSD reader bounds overflow and input-sized allocations
Layer bounds come straight from the file as four i32s. Rect::width/height subtracted them in i32 (overflow: a panic in debug builds, garbage sizes in release), and layer_pixels allocated width x height pixels before reading any data, so a 100-byte file claiming a 2^31-square layer hit "capacity overflow" (or an out-of-memory abort). Widths are now computed in i64 and clamped, every decoded image is capped at 2^28 pixels (Error::Unsupported beyond that), zlib data is inflated with a limit of the expected size, RLE count tables and UTF-16 strings reserve no more than the remaining bytes, and the per-pixel copy only visits the part of the layer that lands in the output. 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
dc573f77e6
@@ -118,7 +118,7 @@ pub(crate) fn read_id(r: &mut Reader) -> Result<String> {
|
||||
|
||||
pub(crate) fn read_unicode(r: &mut Reader) -> Result<String> {
|
||||
let n = r.u32()? as usize;
|
||||
let mut v = Vec::with_capacity(n);
|
||||
let mut v = Vec::with_capacity(n.min(r.remaining() / 2));
|
||||
for _ in 0..n {
|
||||
v.push(r.u16()?);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user