psd icon indicating copy to clipboard operation
psd copied to clipboard

Error: Index out of bounds

Open gregl83 opened this issue 2 years ago • 1 comments

Hi!

Encountering a bug when attempting to load the pixels of each layer in a PSD.

Snippet

let file = fs::File::open(psd_path).expect("file should open read only");

let mut reader = BufReader::new(file);
let mut buffer = Vec::new();

reader.read_to_end(&mut buffer).unwrap();

let psd = Psd::from_bytes(buffer.as_slice()).unwrap();

for layer in psd.layers().iter() {
    let name = layer.name();

    let skip_file = Regex::new(r"^_.*").unwrap();
    if !skip_file.is_match(name) {
        println!("{:?}", name);

        let pixels: Vec<u8> = layer.rgba();
    }
}

Error

thread 'main' panicked at 'index out of bounds: the len is 16384 but the index is 16472', /home/gregl83/.cargo/registry/src/github.com-1ecc6299db9ec823/psd-0.2.0/src/psd_channel.rs:126:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Untested Presumption Layer size can be larger than a PSD project size (dimensions) resulting in overflowed pixels in the PSD overflowing the rgba pixel vector.

gregl83 avatar Oct 30 '21 21:10 gregl83