Skip to content

Commit 7a8cd47

Browse files
Fix crash on loading EXR 2.0 input (#973)
Fixes #966
1 parent 3038f7c commit 7a8cd47

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tools/imageio/exr.imageio/exrinput.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ class ExrInput final : public ImageInput {
3737
}
3838
~ExrInput() {
3939
// FreeEXRVersion(&version); // No need to call, no such function
40-
FreeEXRImage(&image);
40+
if (image.width != 0 && image.height != 0) {
41+
FreeEXRImage(&image);
42+
}
4143
FreeEXRHeader(&header);
4244
FreeEXRErrorMessage(err);
4345
}
@@ -223,6 +225,16 @@ void ExrInput::readImage(void* outputBuffer, size_t bufferByteCount,
223225
"Requested format conversion from the input type is not supported."));
224226
}
225227

228+
// Load image version
229+
EXRVersion exr_version;
230+
ec = ParseEXRVersionFromMemory(&exr_version, exrBuffer.data(), exrBuffer.size());
231+
if (ec != TINYEXR_SUCCESS)
232+
throw std::runtime_error(
233+
fmt::format("EXR load error: {} - {}.", ec, "Failed to parse EXR version"));
234+
if (exr_version.multipart || exr_version.non_image)
235+
throw std::runtime_error(
236+
fmt::format("EXR load error: {}.", "Unsupported EXR version (2.0)"));
237+
226238
// Load image data
227239
ec = LoadEXRImageFromMemory(&image, &header, exrBuffer.data(), exrBuffer.size(), &err);
228240
if (ec != TINYEXR_SUCCESS)

0 commit comments

Comments
 (0)