cessen / openexr-rs

This repository has been moved to https://github.com/vfx-rs/openexr-rs
MIT License
23 stars 10 forks source link

SIGSEGV in CEXR_InputFile_read_pixels if data_window bounds < 0 #30

Closed norru closed 5 years ago

norru commented 5 years ago

I am attempting to load an image, saved by Nuke, whose data_window origin has negative x and y, but I get a 100% SIGSEGV crash (Ubuntu).

        // exr_file: &mut InputFile, loads from an .exr image whose x1,y1 < 0,0

        let (width, height) = exr_file.header().data_dimensions();
        let zero = f16::from_f32(0.0f32);
        println!("Reading pixels from {},{},{}", r_chan, g_chan, b_chan);
        let mut pixel_data = vec![(zero, zero, zero); (width * height) as usize];
        {
            let mut fb = FrameBufferMut::new(width, height);
            println!("Loading buffer as {}x{}", width, height);
            fb.insert_channels(
                &[(r_chan, 0.0), (g_chan, 0.0), (b_chan, 0.0)],
                &mut pixel_data,
            );
            exr_file
                .read_pixels(&mut fb) // crashes here 
                .map_err(|e| io::Error::new(io::ErrorKind::NotFound, e))?;
        }

call [stack:](url

)

0x7ffff798e84a
IlmThread_2_2::ThreadPool::addTask() at 0x7ffff03e927f
Imf_2_2::ScanLineInputFile::readPixels() at 0x7ffff799027a
Imf_2_2::InputFile::readPixels() at 0x7ffff795f8c1
CEXR_InputFile_read_pixels() at cexr.cpp:311 0x55555576eb81

norru commented 5 years ago

Uploaded sample https://github.com/itadinanta/openexr-rs/blob/a1b65c1226eb322fd5619a3b7fd28bf194b4ad70/tests/broken_read.exr?raw=true

cessen commented 5 years ago

Thanks so much for this thorough bug report! I'll take a look at it tomorrow and try to get it fixed ASAP.

norru commented 5 years ago

Thanks :) Let me know if you need more tests/details. I'm also happy to try your fix once it's done if you push it to a branch.

cessen commented 5 years ago

I am also getting that same bug on my machine, and have added a failing test for it. Now just need to track down what's causing it...

cessen commented 5 years ago

Made some progress tracking it down, but I think still have a ways to go. I'll spend some time working on it over the weekend as well, and hopefully can get it tracked down and fixed.

cessen commented 5 years ago

Quick update: still working on it. It's doing a good job of hiding from me, unfortunately.

The next chance I'll likely have to work on this is next weekend. Sorry for the wait! I hope it's not urgent on your side (if it is, let me know and I may be able to prioritize it more).

cessen commented 5 years ago

Unfortunately, I didn't actually end up having time on the weekend. The next few weeks are pretty busy for me, so I likely won't get around to this until after that.

Sorry for the delay! Definitely want to get this fixed.

Also @Ralith, if you happen to have more spare time than me and are inclined, feel free to poke at this. I have a failing test committed for it.

norru commented 5 years ago

No worries. Thanks for your hard work! :)

norru commented 5 years ago

Hey @cessen, @Ralith, I have a fix for this (and a bunch of extras) - have a look at https://github.com/cessen/openexr-rs/pull/31