OpenImageIO
OpenImageIO copied to clipboard
Stress Test: Bad header crashes open
Test case: bad header file.

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.
2.3.10.1
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?
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;
}
