Skip to content

fix: Check op arg counts when loading .oso files - #2231

Merged
lgritz merged 1 commit into
AcademySoftwareFoundation:mainfrom
lgritz:lg-oso-arity
Nov 26, 2026
Merged

lgritz merged 1 commit into
AcademySoftwareFoundation:mainfrom
lgritz:lg-oso-arity

Conversation

@lgritz

@lgritz lgritz commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

We had previously assumed that as long as oslc wrote correct .oso files, liboslexec could make strong assumptions about validity of anything it read. At most, some codegen or constfold functions OSL_DASSERT on the argument numbers and types, mostly to help catch bugs as I was writing the compiler. The DASSERT does nothing in release builds, and a process abort isn't what you'd want when encountering a faulty oso file.

This is, of course, wholly inadequate in a world where a renderer might encounter a corrupted or maliciously crafted oso file. This patch is just one step toward a future of being impervious to inavlid oso.

In this patch, we augment the opcode table in liboslexec to have min and max arity (including being able to say that the max is "any") and check the number of arguments as we are reading the oso file, which lets everything downstream make certain assumptions and precludes whole classes of trouble without needing to change every op individually (the information is all in the central table).

Assisted-by: Claude Code / Claude Opus 5.5

We had previously assumed that as long as oslc wrote a correct .oso
file, liboslexec could make strong assumptions about validity.  At
most, some codegen or constfold functions OSL_DASSERT on the argument
numbers and types, mostly to help catch bugs as I was writing the
compiler. The DASSERT does nothing in release builds, and a process
abort isn't what you'd want when encountering a faulty oso file.

This is, of course, wholly inadequate in a world where a renderer
might encounter a corrupted or maliciously crafted oso file.  This
patch is just one step toward a future of being impervious to inavlid
oso.

In this patch, we augment the opcode table in liboslexec to have min
and max arity (including being able to say that the max is "any") and
check the number of arguments as we are reading the oso file, which
lets everything downstream make certain assumptions and precludes
whole classes of trouble without needing to change every op
individually (the information is all in the central table).

Assisted-by: Claude Code / Claude Opus 5.5

Signed-off-by: Larry Gritz <lg@larrygritz.com>
@lgritz
lgritz merged commit 073f1a2 into AcademySoftwareFoundation:main Nov 26, 2026
22 of 23 checks passed
@lgritz
lgritz deleted the lg-oso-arity branch November 30, 2026 22:11
lgritz added a commit to lgritz/OpenShadingLanguage that referenced this pull request Nov 30, 2026
…dation#2231)

We had previously assumed that as long as oslc wrote a correct .oso
file, liboslexec could make strong assumptions about validity.  At
most, some codegen or constfold functions OSL_DASSERT on the argument
numbers and types, mostly to help catch bugs as I was writing the
compiler. The DASSERT does nothing in release builds, and a process
abort isn't what you'd want when encountering a faulty oso file.

This is, of course, wholly inadequate in a world where a renderer
might encounter a corrupted or maliciously crafted oso file.  This
patch is just one step toward a future of being impervious to inavlid
oso.

In this patch, we augment the opcode table in liboslexec to have min
and max arity (including being able to say that the max is "any") and
check the number of arguments as we are reading the oso file, which
lets everything downstream make certain assumptions and precludes
whole classes of trouble without needing to change every op
individually (the information is all in the central table).

Assisted-by: Claude Code / Claude Opus 5.5

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