Skip to content

Commit

Permalink
fix(rla): More robust to corrupted RLA files that could overrun buffe…
Browse files Browse the repository at this point in the history
…rs (#4624)

Signed-off-by: Larry Gritz <[email protected]>
  • Loading branch information
lgritz authored Feb 14, 2025
1 parent 4065e6f commit aaa599b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/rla.imageio/rlainput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,15 @@ RLAInput::decode_channel_group(int first_channel, short num_channels,
// OIIO conventions.
if (num_bits == 8 || num_bits == 16 || num_bits == 32) {
// ok -- no rescaling needed
} else if (num_bits == 10) {
}
int bytes_per_chan = ceil2(std::max(int(num_bits), 8)) / 8;
if (size_t(offset + (m_spec.width - 1) * pixelsize
+ num_channels * bytes_per_chan)
> m_buf.size()) {
errorfmt("Probably corrupt file (buffer overrun avoided)");
return false; // Probably corrupt? Would have overrun
}
if (num_bits == 10) {
// fast, common case -- use templated hard-code
for (int x = 0; x < m_spec.width; ++x) {
uint16_t* b = (uint16_t*)(&m_buf[offset + x * pixelsize]);
Expand Down
3 changes: 3 additions & 0 deletions testsuite/rla/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,5 +319,8 @@ Full command line was:
oiiotool ERROR: read : "src/crash-3951.rla": Read error: couldn't read RLE data span
Full command line was:
> oiiotool src/crash-3951.rla -o crash4.exr
oiiotool ERROR: read : "src/crash-1.rla": Probably corrupt file (buffer overrun avoided)
Full command line was:
> oiiotool src/crash-1.rla -o crash5.exr
Comparing "rlacrop.rla" and "ref/rlacrop.rla"
PASS
1 change: 1 addition & 0 deletions testsuite/rla/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
command += oiiotool(OIIO_TESTSUITE_IMAGEDIR + "/crash2.rla -o crash2.exr", failureok = True)
command += oiiotool("src/crash-1629.rla -o crash3.exr", failureok = True)
command += oiiotool("src/crash-3951.rla -o crash4.exr", failureok = True)
command += oiiotool("src/crash-1.rla -o crash5.exr", failureok = True)

outputs = [ "rlacrop.rla", 'out.txt' ]
Binary file added testsuite/rla/src/crash-1.rla
Binary file not shown.

0 comments on commit aaa599b

Please sign in to comment.