Skip to content

Commit

Permalink
Fix crash on loading EXR 2.0 input
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasMagnus committed Jan 6, 2025
1 parent 3038f7c commit ea1d50e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tools/imageio/exr.imageio/exrinput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class ExrInput final : public ImageInput {
}
~ExrInput() {
// FreeEXRVersion(&version); // No need to call, no such function
FreeEXRImage(&image);
if (image.width != 0 && image.height != 0) {
FreeEXRImage(&image);
}
FreeEXRHeader(&header);
FreeEXRErrorMessage(err);
}
Expand Down Expand Up @@ -223,6 +225,16 @@ void ExrInput::readImage(void* outputBuffer, size_t bufferByteCount,
"Requested format conversion from the input type is not supported."));
}

// Load image version
EXRVersion exr_version;
ec = ParseEXRVersionFromMemory(&exr_version, exrBuffer.data(), exrBuffer.size());
if (ec != TINYEXR_SUCCESS)
throw std::runtime_error(
fmt::format("EXR load error: {} - {}.", ec, "Failed to parse EXR version"));
if (exr_version.multipart || exr_version.non_image)
throw std::runtime_error(
fmt::format("EXR load error: {}.", "Unsupported EXR version (2.0)"));

// Load image data
ec = LoadEXRImageFromMemory(&image, &header, exrBuffer.data(), exrBuffer.size(), &err);
if (ec != TINYEXR_SUCCESS)
Expand Down

0 comments on commit ea1d50e

Please sign in to comment.