OpenImageIO icon indicating copy to clipboard operation
OpenImageIO copied to clipboard

Stress Test: Bad header crashes open

Open DougRogers opened this issue 3 years ago • 4 comments

Test case: bad header file.
bad-header

DougRogers avatar Jan 24 '22 01:01 DougRogers

Which version of OIIO?

On my end, it detects the bad header and sends an error message that says "Not a PNG file". Maybe this is one of the problems we've already fixed.

lgritz avatar Jan 24 '22 06:01 lgritz

2.3.10.1

DougRogers avatar Jan 24 '22 07:01 DougRogers

No luck, I get a graceful error message, even with 2.3.10.1.

Do you have a specific command line that I can run identically that can reproduce it, like

iinfo -v -stats bad.png
iconvert bad.png out.tif

Do you have a stack trace?

lgritz avatar Jan 24 '22 22:01 lgritz

I have a simple test program.

#define READ_IMAGE 0
#include <string>
#include <iostream>
#include <filesystem>

namespace fs = std::filesystem;
#include <OpenImageIO/imageio.h>
using namespace OIIO;

int count;
int main(int argc, char *argv[])
{
    // std::string path = "J:/";

    std::string path = "F:/";

    for (const auto &entry : fs::directory_iterator(path))
    // for (const auto &entry : fs::recursive_directory_iterator(path))
    {
        // std::cout << entry.path() << std::endl;
        QString filePath = QString::fromStdWString(entry.path().wstring());

        if (QtHelper::supportedFileType(filePath) && !QtHelper::isVideo(filePath))
        {

            printf("Count %d\n", ++count);
            fflush(stdout);

            ImageSpec config;
            config["oiio:UnassociatedAlpha"] = 1;

            std::string fileName = entry.path().string();
            auto inp             = ImageInput::open(fileName.c_str(), &config);
            if (inp)
            {
#if READ_IMAGE
                const ImageSpec &spec = inp->spec();
                int xres              = spec.width;
                int yres              = spec.height;
                int channels          = spec.nchannels;
                std::vector<unsigned char> pixels(xres * yres * channels);
                inp->read_image(TypeDesc::UINT8, &pixels[0]);
#endif
                inp->close();
            }
            else
            {
                qDebug() << "Cannot open file " << filePath;
            }
        }
    }
    return 1;
}

image

DougRogers avatar Jan 24 '22 23:01 DougRogers