Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/lib/OpenEXRCore/part_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,12 @@ exr_attr_set_preview (
{
size_t copybytes =
(size_t) val->width * (size_t) val->height * (size_t) 4;
if (copybytes > 0 && !val->rgba)
return EXR_UNLOCK_AND_RETURN (ctxt->print_error (
ctxt,
EXR_ERR_INVALID_ARGUMENT,
"Invalid NULL preview rgba data for setting '%s'",
name));
memcpy (
EXR_CONST_CAST (void*, attr->preview->rgba),
val->rgba,
Expand Down
18 changes: 12 additions & 6 deletions src/lib/OpenEXRCore/preview.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,19 @@ exr_attr_preview_create (
uint32_t h,
const uint8_t* d)
{
size_t copybytes = (size_t) w * (size_t) h * (size_t) 4;

if (copybytes > 0 && !d)
return ctxt->print_error (
ctxt,
EXR_ERR_INVALID_ARGUMENT,
"Invalid NULL preview rgba data for %u x %u preview",
w,
h);

exr_result_t rv = exr_attr_preview_init (ctxt, p, w, h);
if (rv == EXR_ERR_SUCCESS)
{
size_t copybytes = w * h * 4;
if (copybytes > 0)
memcpy (EXR_CONST_CAST (uint8_t*, p->rgba), d, copybytes);
}
if (rv == EXR_ERR_SUCCESS && copybytes > 0)
memcpy (EXR_CONST_CAST (uint8_t*, p->rgba), d, copybytes);
return rv;
}

Expand Down
29 changes: 29 additions & 0 deletions src/test/OpenEXRCoreTest/general_attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,35 @@ testPreviewHelper (exr_context_t f)
// make sure we can re-delete something?
EXRCORE_TEST_RVAL (exr_attr_preview_destroy (f, &p));

EXRCORE_TEST_RVAL_FAIL (
EXR_ERR_INVALID_ARGUMENT, exr_attr_preview_create (f, &p, 1, 1, NULL));

{
exr_attr_preview_t preview;
preview.width = 1;
preview.height = 1;
preview.alloc_size = 0;
preview.rgba = NULL;
EXRCORE_TEST_RVAL_FAIL (
EXR_ERR_INVALID_ARGUMENT,
exr_attr_set_preview (f, 0, "badPreview", &preview));
}

{
exr_attr_preview_t preview;
preview.width = 1;
preview.height = 1;
preview.alloc_size = 4;
preview.rgba = data1x1;
EXRCORE_TEST_RVAL (
exr_attr_set_preview (f, 0, "goodPreview", &preview));

preview.rgba = NULL;
EXRCORE_TEST_RVAL_FAIL (
EXR_ERR_INVALID_ARGUMENT,
exr_attr_set_preview (f, 0, "goodPreview", &preview));
}

EXRCORE_TEST_RVAL_FAIL_MALLOC (
EXR_ERR_OUT_OF_MEMORY, exr_attr_preview_create (f, &p, 1, 1, data1x1));
}
Expand Down
Loading