diff options
| author | ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> | 2024-07-19 14:52:25 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-19 11:52:25 -0700 |
| commit | 4ae58a720e6f8d63ff5c74fd14f630137dfd0c0c (patch) | |
| tree | 25d3e4813d0cbd25090cef9870b36f3c6930483a /source | |
| parent | f114433debfba67cbe1db239b6e92278d41ed438 (diff) | |
Fix for invalid swizzle causing crash (#4690)
* Fix for invalid swizzle causing crash
Fixes #4689
If swizzle code is provided 5+ element swizzle the checkSwizzleExpr code will do an out of bounds array access and crash.
* switch test to check for to ensure no crash
* cleanup swizzle errors to only emit once
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-check-expr.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index f60ead1e9..fd03e5e87 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -3743,9 +3743,8 @@ namespace Slang case 'w': case 'a': elementIndex = 3; break; default: // An invalid character in the swizzle is an error - getSink()->diagnose(swizExpr, Diagnostics::invalidSwizzleExpr, swizzleText, baseElementType->toString()); anyError = true; - continue; + break; } // TODO(tfoley): GLSL requires that all component names @@ -3754,9 +3753,16 @@ namespace Slang // Make sure the index is in range for the source type if (elementIndex >= limitElement) { - getSink()->diagnose(swizExpr, Diagnostics::invalidSwizzleExpr, swizzleText, baseElementType->toString()); anyError = true; - continue; + break; + } + + // If elementCount is already at 4 stop trying to assign a swizzle element and send an error, + // we cannot have more valid swizzle elements than 4. + if (elementCount >= 4) + { + anyError = true; + break; } // Check if we've seen this index before @@ -3778,6 +3784,7 @@ namespace Slang if (anyError) { + getSink()->diagnose(swizExpr, Diagnostics::invalidSwizzleExpr, swizzleText, baseElementType->toString()); return CreateErrorExpr(memberRefExpr); } else if (elementCount == 1) |
