Skip to content

Commit cdccb84

Browse files
committed
remove extra allocation, fix invalid dereference on corrupt file
Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
1 parent e8e0b99 commit cdccb84

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/lib/OpenEXRCore/internal_ht.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,17 @@ internal_exr_undo_ht (
177177
if (decode->channel_count != cs_to_file_ch.size ())
178178
throw std::runtime_error ("Unexpected number of channels");
179179

180-
std::vector<size_t> offsets (decode->channel_count);
181-
offsets[0] = 0;
182-
for (int file_i = 1; file_i < decode->channel_count; file_i++)
183-
{
184-
offsets[file_i] = offsets[file_i - 1] +
185-
decode->channels[file_i - 1].width *
186-
decode->channels[file_i - 1].bytes_per_element;
187-
}
188180
for (int cs_i = 0; cs_i < decode->channel_count; cs_i++)
189181
{
190-
cs_to_file_ch[cs_i].raster_line_offset =
191-
offsets[cs_to_file_ch[cs_i].file_index];
182+
int file_i = cs_to_file_ch[cs_i].file_index;
183+
if (file_i >= decode->channel_count)
184+
return EXR_ERR_CORRUPT_CHUNK;
185+
186+
size_t computedoffset = 0;
187+
for (int i = 0; i < file_i; ++i)
188+
computedoffset += decode->channels[i].width *
189+
decode->channels[i].bytes_per_element;
190+
cs_to_file_ch[cs_i].raster_line_offset = computedoffset;
192191
}
193192

194193
ojph::mem_infile infile;

0 commit comments

Comments
 (0)