Skip to content

Commit 33088a5

Browse files
committed
1 parent 0815913 commit 33088a5

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

pxr/imaging/hio/OpenEXR/OpenEXRCore/decoding.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ default_decompress_chunk (exr_decode_pipeline_t* decode)
288288
uint64_t sampsize =
289289
(((uint64_t) decode->chunk.width) *
290290
((uint64_t) decode->chunk.height));
291+
292+
if ((decode->decode_flags & EXR_DECODE_SAMPLE_COUNTS_AS_INDIVIDUAL))
293+
sampsize += 1;
291294
sampsize *= sizeof (int32_t);
292295

293296
rv = decompress_data (
@@ -340,7 +343,7 @@ unpack_sample_table (
340343
exr_result_t rv = EXR_ERR_SUCCESS;
341344
int32_t w = decode->chunk.width;
342345
int32_t h = decode->chunk.height;
343-
int32_t totsamp = 0;
346+
uint64_t totsamp = 0;
344347
int32_t* samptable = decode->sample_count_table;
345348
size_t combSampSize = 0;
346349

@@ -351,38 +354,44 @@ unpack_sample_table (
351354
{
352355
for (int32_t y = 0; y < h; ++y)
353356
{
357+
int32_t *cursampline = samptable + y * w;
354358
int32_t prevsamp = 0;
355359
for (int32_t x = 0; x < w; ++x)
356360
{
357361
int32_t nsamps =
358-
(int32_t) one_to_native32 ((uint32_t) samptable[y * w + x]);
359-
if (nsamps < 0) return EXR_ERR_INVALID_SAMPLE_DATA;
360-
samptable[y * w + x] = nsamps - prevsamp;
361-
prevsamp = nsamps;
362+
(int32_t) one_to_native32 ((uint32_t) cursampline[x]);
363+
if (nsamps < prevsamp) return EXR_ERR_INVALID_SAMPLE_DATA;
364+
365+
cursampline[x] = nsamps - prevsamp;
366+
prevsamp = nsamps;
362367
}
363-
totsamp += prevsamp;
368+
totsamp += (uint64_t)prevsamp;
364369
}
365-
samptable[w * h] = totsamp;
370+
if (totsamp >= (uint64_t)INT32_MAX)
371+
return EXR_ERR_INVALID_SAMPLE_DATA;
372+
samptable[w * h] = (int32_t)totsamp;
366373
}
367374
else
368375
{
369376
for (int32_t y = 0; y < h; ++y)
370377
{
378+
int32_t *cursampline = samptable + y * w;
371379
int32_t prevsamp = 0;
372380
for (int32_t x = 0; x < w; ++x)
373381
{
374382
int32_t nsamps =
375-
(int32_t) one_to_native32 ((uint32_t) samptable[y * w + x]);
376-
if (nsamps < 0) return EXR_ERR_INVALID_SAMPLE_DATA;
377-
samptable[y * w + x] = nsamps;
378-
prevsamp = nsamps;
383+
(int32_t) one_to_native32 ((uint32_t) cursampline[x]);
384+
if (nsamps < prevsamp) return EXR_ERR_INVALID_SAMPLE_DATA;
385+
386+
cursampline[x] = nsamps;
387+
prevsamp = nsamps;
379388
}
380-
totsamp += prevsamp;
389+
390+
totsamp += (uint64_t)prevsamp;
381391
}
382392
}
383393

384-
if (totsamp < 0 ||
385-
(((uint64_t) totsamp) * combSampSize) > decode->chunk.unpacked_size)
394+
if ((totsamp * combSampSize) > decode->chunk.unpacked_size)
386395
{
387396
rv = pctxt->report_error (
388397
pctxt, EXR_ERR_INVALID_SAMPLE_DATA, "Corrupt sample count table");

pxr/imaging/hio/OpenEXR/OpenEXRCore/unpack.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,9 +1196,10 @@ generic_unpack_deep_pointers (exr_decode_pipeline_t* decode)
11961196
if (outpix)
11971197
{
11981198
uint8_t* cdata = outpix;
1199+
11991200
UNPACK_SAMPLES (samps)
12001201
}
1201-
srcbuffer += bpc * samps;
1202+
srcbuffer += ((size_t) bpc) * ((size_t) samps);
12021203
}
12031204
}
12041205
sampbuffer += w;
@@ -1242,12 +1243,14 @@ generic_unpack_deep (exr_decode_pipeline_t* decode)
12421243
}
12431244
else
12441245
prevsamps = sampbuffer[w - 1];
1246+
12451247
srcbuffer += ((size_t) bpc) * ((size_t) prevsamps);
12461248

12471249
if (incr_tot) totsamps += (size_t) prevsamps;
12481250

12491251
continue;
12501252
}
1253+
12511254
cdata += totsamps * ((size_t) ubpc);
12521255

12531256
for (int x = 0; x < w; ++x)
@@ -1263,7 +1266,7 @@ generic_unpack_deep (exr_decode_pipeline_t* decode)
12631266

12641267
UNPACK_SAMPLES (samps)
12651268

1266-
srcbuffer += bpc * samps;
1269+
srcbuffer += ((size_t) bpc) * ((size_t) samps);
12671270
if (incr_tot) totsamps += (size_t) samps;
12681271
}
12691272
}
@@ -1301,7 +1304,7 @@ internal_exr_match_decode (
13011304

13021305
if (isdeep)
13031306
{
1304-
if ((decode->decode_flags & EXR_DECODE_SAMPLE_COUNTS_AS_INDIVIDUAL))
1307+
if ((decode->decode_flags & EXR_DECODE_NON_IMAGE_DATA_AS_POINTERS))
13051308
return &generic_unpack_deep_pointers;
13061309
return &generic_unpack_deep;
13071310
}

0 commit comments

Comments
 (0)