We had some issues with PNG and Jpeg files not opening on Windows with the 
error being reported they were’t their respective formats, the same code worked 
perfectly fine on macOS and Linux with the same image files. 

(this is with OIIO 2.1.1)

After some digging it was due to headers/magic numbers being read and then the 
file handle not being reset.  

For instance, in pnginput.cpp we’ve added

m_io->seek(m_io_offset);

to line 190, after the initial m_io->pread and before the PNG_pvt::read_info 
otherwise read_info fails because it tries to read the header again to confirm 
it’s a PNG file but because the pointer hasn’t been reset it fails. 

The same was done for jpeginput.cpp, ie. 

    if (io) {
        int64_t io_offset = m_io->tell();
        ok = (io->pread(magic, sizeof(magic), 0) == sizeof(magic));
        io->seek(io_offset);
    } else {

was used in valid_file and the same sort of thing done in open:

    int64_t io_offset = m_io->tell();
    // Check magic number to assure this is a JPEG file
    uint8_t magic[2] = { 0, 0 };
    if (m_io->pread(magic, sizeof(magic), 0) != sizeof(magic)) {
        errorf("Empty file \"%s\"", name);
        close_file();
        return false;
    }
    m_io->seek(io_offset);

This doesn’t seem to break the other platforms but makes these calls succeed on 
Windows.  I assume there’s a different file pointer behaviour on Windows vs. 
the other platforms but not too sure if there’s anything specific in the 
IOProxy class that treats the platforms differently?

I realize we’re using a slightly older release so this may have already been 
resolved, but thought it was worth pointing out. 

Happy Labour Day weekend! 

Colin


_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to