Skip to content

fix(rla): lots of additional validity checking and safety#5094

Merged
lgritz merged 2 commits intoAcademySoftwareFoundation:mainfrom
lgritz:lg-rlafix
Mar 23, 2026
Merged

fix(rla): lots of additional validity checking and safety#5094
lgritz merged 2 commits intoAcademySoftwareFoundation:mainfrom
lgritz:lg-rlafix

Conversation

@lgritz
Copy link
Collaborator

@lgritz lgritz commented Mar 18, 2026

  • Validity-check resolution of RLA files with check_open. RLA file headers contain int16_t values for left & right (and top/bottom) window coordinate, leading to a maximum resolution of 2^16-1.

  • Fix potential bug with sign extension in RLE decoding -- if a signed char is -128, negating it can't make signed char 128 (no such thing), so must widen the var to an int.

  • Fix potential bug by detecting when the number of matte or auxiliary bits is 0, but the number of matte or aux channels, respectively, is not.

  • Better bounds checking in decode_channel_group. We did the checks before, but after some accesses that would have been out of bounds! Move the checks earlier than all the accesses. It actually looks like was the result of a cut and paste error long ago.

  • More care in read_native_scanline for checking valid scanline numbers, offset into m_sot, and check whether ioseek succeeded (i.e. whether the offsets loaded from the file are within the range of the size of the file).

Code and fixes all are from my own brain, but some of the analysis of which spots have bounds issues were identified in part by conversation with Claude Code Opus 4.6.

* Validity-check resolution of RLA files with check_open.  RLA file
  headers contain int16_t values for left & right (and top/bottom)
  window coordinate, leading to a maximum resolution of 2^16-1.

* Fix potential bug with sign extension in RLE decoding -- if a signed
  char is -128, negating it can't make signed char 128 (no such
  thing), so must widen the var to an int.

* Fix potential bug by detecting when the number of matte or auxiliary
  bits is 0, but the number of matte or aux channels, respectively, is
  not.

* Better bounds checking in decode_channel_group. We did the checks
  before, but after some accesses that would have been out of bounds!
  Move the checks earlier than all the accesses. It actually looks like
  was the result of a cut and paste error long ago.

* More care in read_native_scanline for checking valid scanline
  numbers, offset into m_sot, and check whether ioseek succeeded
  (i.e. whether the offsets loaded from the file are within the range
  of the size of the file).

Code and fixes all are from my own brain, but some of the spots with
bounds issues were identified in part by conversation with Claude Code
Opus 4.6.

Assisted-by: Claude Code / Opus 4.6
Signed-off-by: Larry Gritz <lg@larrygritz.com>
@lgritz
Copy link
Collaborator Author

lgritz commented Mar 23, 2026

Comments or objections?

Copy link
Contributor

@jessey-git jessey-git left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look fine minus 1 nit.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
@lgritz lgritz merged commit ab3905a into AcademySoftwareFoundation:main Mar 23, 2026
31 checks passed
@lgritz lgritz deleted the lg-rlafix branch March 23, 2026 19:38
lgritz added a commit to lgritz/OpenImageIO that referenced this pull request Mar 23, 2026
…twareFoundation#5094)

* Validity-check resolution of RLA files with check_open. RLA file
headers contain int16_t values for left & right (and top/bottom) window
coordinate, leading to a maximum resolution of 2^16-1.

* Fix potential bug with sign extension in RLE decoding -- if a signed
char is -128, negating it can't make signed char 128 (no such thing), so
must widen the var to an int.

* Fix potential bug by detecting when the number of matte or auxiliary
bits is 0, but the number of matte or aux channels, respectively, is
not.

* Better bounds checking in decode_channel_group. We did the checks
before, but after some accesses that would have been out of bounds! Move
the checks earlier than all the accesses. It actually looks like was the
result of a cut and paste error long ago.

* More care in read_native_scanline for checking valid scanline numbers,
offset into m_sot, and check whether ioseek succeeded (i.e. whether the
offsets loaded from the file are within the range of the size of the
file).

Code and fixes all are from my own brain, but some of the analysis of
which spots have bounds issues were identified in part by conversation
with Claude Code Opus 4.6.

---------

Signed-off-by: Larry Gritz <lg@larrygritz.com>
lgritz added a commit to lgritz/OpenImageIO that referenced this pull request Mar 24, 2026
…twareFoundation#5094)

* Validity-check resolution of RLA files with check_open. RLA file
headers contain int16_t values for left & right (and top/bottom) window
coordinate, leading to a maximum resolution of 2^16-1.

* Fix potential bug with sign extension in RLE decoding -- if a signed
char is -128, negating it can't make signed char 128 (no such thing), so
must widen the var to an int.

* Fix potential bug by detecting when the number of matte or auxiliary
bits is 0, but the number of matte or aux channels, respectively, is
not.

* Better bounds checking in decode_channel_group. We did the checks
before, but after some accesses that would have been out of bounds! Move
the checks earlier than all the accesses. It actually looks like was the
result of a cut and paste error long ago.

* More care in read_native_scanline for checking valid scanline numbers,
offset into m_sot, and check whether ioseek succeeded (i.e. whether the
offsets loaded from the file are within the range of the size of the
file).

Code and fixes all are from my own brain, but some of the analysis of
which spots have bounds issues were identified in part by conversation
with Claude Code Opus 4.6.

---------

Signed-off-by: Larry Gritz <lg@larrygritz.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants