Skip to content

Commit aaa599b

Browse files
authored
fix(rla): More robust to corrupted RLA files that could overrun buffers (#4624)
Signed-off-by: Larry Gritz <[email protected]>
1 parent 4065e6f commit aaa599b

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

src/rla.imageio/rlainput.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,15 @@ RLAInput::decode_channel_group(int first_channel, short num_channels,
604604
// OIIO conventions.
605605
if (num_bits == 8 || num_bits == 16 || num_bits == 32) {
606606
// ok -- no rescaling needed
607-
} else if (num_bits == 10) {
607+
}
608+
int bytes_per_chan = ceil2(std::max(int(num_bits), 8)) / 8;
609+
if (size_t(offset + (m_spec.width - 1) * pixelsize
610+
+ num_channels * bytes_per_chan)
611+
> m_buf.size()) {
612+
errorfmt("Probably corrupt file (buffer overrun avoided)");
613+
return false; // Probably corrupt? Would have overrun
614+
}
615+
if (num_bits == 10) {
608616
// fast, common case -- use templated hard-code
609617
for (int x = 0; x < m_spec.width; ++x) {
610618
uint16_t* b = (uint16_t*)(&m_buf[offset + x * pixelsize]);

testsuite/rla/ref/out.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,5 +319,8 @@ Full command line was:
319319
oiiotool ERROR: read : "src/crash-3951.rla": Read error: couldn't read RLE data span
320320
Full command line was:
321321
> oiiotool src/crash-3951.rla -o crash4.exr
322+
oiiotool ERROR: read : "src/crash-1.rla": Probably corrupt file (buffer overrun avoided)
323+
Full command line was:
324+
> oiiotool src/crash-1.rla -o crash5.exr
322325
Comparing "rlacrop.rla" and "ref/rlacrop.rla"
323326
PASS

testsuite/rla/run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
command += oiiotool(OIIO_TESTSUITE_IMAGEDIR + "/crash2.rla -o crash2.exr", failureok = True)
2323
command += oiiotool("src/crash-1629.rla -o crash3.exr", failureok = True)
2424
command += oiiotool("src/crash-3951.rla -o crash4.exr", failureok = True)
25+
command += oiiotool("src/crash-1.rla -o crash5.exr", failureok = True)
2526

2627
outputs = [ "rlacrop.rla", 'out.txt' ]

testsuite/rla/src/crash-1.rla

772 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)