Skip to content

Commit 6c0ecf5

Browse files
committed
fix(rla): Improve robustness for currupt files
Clean up seeking methodology to be more robust. Fixes 5159 Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent c950727 commit 6c0ecf5

4 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/rla.imageio/rlainput.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,18 @@ RLAInput::seek_subimage(int subimage, int miplevel)
246246
if (!read_header())
247247
return false; // read_header always calls error()
248248
diff = subimage;
249+
m_subimage = 0;
249250
}
250251
// forward scrolling -- skip subimages until we're at the right place
251-
while (diff > 0 && m_rla.NextOffset != 0) {
252+
while (diff > 0 && m_subimage < subimage && m_rla.NextOffset != 0) {
252253
if (!ioseek(m_rla.NextOffset)) {
253254
errorfmt("Could not seek to header offset. Corrupted file?");
254255
return false;
255256
}
256257
if (!read_header())
257258
return false; // read_header always calls error()
258259
--diff;
260+
++m_subimage;
259261
}
260262
if (diff > 0 && m_rla.NextOffset == 0) { // no more subimages to read
261263
errorfmt("Unknown subimage");
@@ -545,7 +547,7 @@ RLAInput::decode_channel_group(int first_channel, short num_channels,
545547
offset = 0;
546548
pixelsize = m_spec.pixel_bytes(true);
547549
for (int i = 0; i < first_channel; ++i)
548-
offset += m_spec.channelformats[i].size();
550+
offset += m_spec.channelformat(i).size();
549551
}
550552

551553
// Read the big-endian values into the buffer.

testsuite/rla/ref/out.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,5 +325,8 @@ Full command line was:
325325
oiiotool ERROR: read : "src/crash-5152.rla": Read error: malformed RLE record
326326
Full command line was:
327327
> oiiotool src/crash-5152.rla -o crash6.exr
328+
oiiotool ERROR: read : "src/crash-5159.rla": Read error: couldn't read RLE data span
329+
Full command line was:
330+
> oiiotool src/crash-5159.rla -o crash7.exr
328331
Comparing "rlacrop.rla" and "ref/rlacrop.rla"
329332
PASS

testsuite/rla/run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424
command += oiiotool("src/crash-3951.rla -o crash4.exr", failureok = True)
2525
command += oiiotool("src/crash-1.rla -o crash5.exr", failureok = True)
2626
command += oiiotool("src/crash-5152.rla -o crash6.exr", failureok = True)
27+
command += oiiotool("src/crash-5159.rla -o crash7.exr", failureok = True)
2728

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

testsuite/rla/src/crash-5159.rla

1.04 KB
Binary file not shown.

0 commit comments

Comments
 (0)