Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid accessing empty vector in realloc_deepdata in checkCoreFile #1648

Closed
Closed
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
31 changes: 18 additions & 13 deletions src/lib/OpenEXRUtil/ImfCheckFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1210,10 +1210,8 @@ realloc_deepdata(exr_decode_pipeline_t* decode)
int32_t h = decode->chunk.height;
uint64_t totsamps = 0, bytes = 0;
const int32_t *sampbuffer = decode->sample_count_table;
std::vector<uint8_t>* ud = static_cast<std::vector<uint8_t>*>(
decode->decoding_user_data);

if ( ! ud )
if ( decode->decoding_user_data == nullptr )
{
for (int c = 0; c < decode->channel_count; c++)
{
Expand Down Expand Up @@ -1259,23 +1257,30 @@ realloc_deepdata(exr_decode_pipeline_t* decode)
return EXR_ERR_SUCCESS;
}

if (ud->size () < bytes)
std::vector<uint8_t>& ud = *static_cast<std::vector<uint8_t>*>(decode->decoding_user_data);

if (ud.size () < bytes)
{
ud->resize (bytes);
if (ud->capacity() < bytes)
ud.resize (bytes);
if (ud.capacity() < bytes)
return EXR_ERR_OUT_OF_MEMORY;
}

uint8_t* dptr = &((*ud)[0]);
for (int c = 0; c < decode->channel_count; c++)
if (ud.size() > 0)
{
exr_coding_channel_info_t& outc = decode->channels[c];
outc.decode_to_ptr = dptr;
outc.user_pixel_stride = outc.user_bytes_per_element;
outc.user_line_stride = 0;
uint8_t* dptr = ud.data();

for (int c = 0; c < decode->channel_count; c++)
{
exr_coding_channel_info_t& outc = decode->channels[c];
outc.decode_to_ptr = dptr;
outc.user_pixel_stride = outc.user_bytes_per_element;
outc.user_line_stride = 0;

dptr += totsamps * (uint64_t) outc.user_bytes_per_element;
dptr += totsamps * (uint64_t) outc.user_bytes_per_element;
}
}

return EXR_ERR_SUCCESS;
}

Expand Down
Loading