Skip to content

Commit db5ed90

Browse files
authored
htj2k compressor: validate codestream dimensions (#2403)
Signed-off-by: Pierre-Anthony Lemieux <pal@palemieux.com>
1 parent 736a335 commit db5ed90

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/lib/OpenEXRCore/internal_ht.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,25 @@ ht_undo_impl (
204204

205205
ojph::ui32 image_height =
206206
siz.get_image_extent ().y - siz.get_image_offset ().y;
207+
ojph::ui32 image_width =
208+
siz.get_image_extent ().x - siz.get_image_offset ().x;
207209

208-
if (decode->chunk.width != siz.get_image_extent ().x - siz.get_image_offset ().x
210+
if (decode->chunk.width != image_width
209211
|| decode->chunk.height != image_height
210212
|| decode->channel_count != siz.get_num_components())
211213
return EXR_ERR_CORRUPT_CHUNK;
212214

215+
for (int cs_i = 0; cs_i < decode->channel_count; cs_i++)
216+
{
217+
int file_i = cs_to_file_ch[cs_i].file_index;
218+
219+
if (decode->channels[file_i].height != siz.get_recon_height (cs_i) ||
220+
decode->channels[file_i].width != siz.get_recon_width (cs_i) ||
221+
decode->channels[file_i].height != image_height / siz.get_downsampling (cs_i).y ||
222+
decode->channels[file_i].width != image_width / siz.get_downsampling (cs_i).x)
223+
return EXR_ERR_CORRUPT_CHUNK;
224+
}
225+
213226
int64_t bpl = 0;
214227
bool is_planar = false;
215228
for (int16_t c = 0; c < decode->channel_count; c++)
@@ -235,9 +248,6 @@ ht_undo_impl (
235248
for (int16_t c = 0; c < decode->channel_count; c++)
236249
{
237250
int file_c = cs_to_file_ch[c].file_index;
238-
assert (
239-
siz.get_recon_height (c) == decode->channels[file_c].height);
240-
assert (decode->channels[file_c].width == siz.get_recon_width (c));
241251

242252
if (decode->channels[file_c].height == 0) continue;
243253

0 commit comments

Comments
 (0)