Fix multiple NullReferenceException issues - doubles success rate to 62%#72
Merged
Conversation
## Summary This PR fixes critical NullReferenceException bugs that caused Unluau to crash on many real-world Luau bytecode files. The success rate is improved from ~30% to ~62%. ## Problem - Unluau crashed with NullReferenceException when encountering unsupported bytecode instructions - Only small files (<3KB) could be decompiled successfully - Success rate was only 30% on real-world files ## Solution Added null checks in 9 critical locations where the decompiler attempted to use null values: ### Files Modified: - `src/Unluau/Lifter/Lifter.cs` - Added null checks in SETTABLEKS, SETTABLE, NAMECALL handlers - `src/Unluau/Lifter/Statements/IfElse.cs` - Check Condition and IfBody for null - `src/Unluau/Lifter/Expressions/NameIndex.cs` - Check Expression for null - `src/Unluau/Lifter/Statements/LocalAssignment.cs` - Check Expression and Value for null - `src/Unluau/Lifter/Statements/Assignment.cs` - Check Variable and Value for null - `src/Unluau/Lifter/Expressions/BinaryExpression.cs` - Check Left and Right for null - `src/Unluau/Lifter/Statements/Return.cs` - Handle null expressions in list - `src/Unluau/Lifter/Statements/Statement.cs` - Check for null statements in sequence - `src/Unluau/Lifter/Expressions/Closure.cs` - Check Block for null ## Results ### Before: - ✅ 4/13 files (30% success rate) - ❌ Frequent NullReferenceException crashes - ❌ Max file size: ~3KB ### After: - ✅ 8/13 files (62% success rate) - ✅ No crashes - graceful handling of unsupported instructions - ✅ Max file size: 19.74KB - ✅ Files with JUMP, FORNLOOP instructions now produce partial output instead of crashing ## Testing Tested with 13 real-world Luau bytecode files ranging from 1.5KB to 53KB. Test files are available in issue #[issue-number]. ## Notes The 5 remaining files that don't decompile appear to use bytecode instructions that Unluau doesn't support yet (JUMP, FORNLOOP, etc.), but at least they no longer crash the decompiler. Fixes #[71]
Fix multiple NullReferenceException issues - doubles success rate to 62%
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes critical NullReferenceException bugs that caused Unluau to crash on many real-world Luau bytecode files. The success rate is improved from ~30% to ~62%.
Problem
Solution
Added null checks in 9 critical locations where the decompiler attempted to use null values:
Files Modified:
src/Unluau/Lifter/Lifter.cs- Added null checks in SETTABLEKS, SETTABLE, NAMECALL handlerssrc/Unluau/Lifter/Statements/IfElse.cs- Check Condition and IfBody for nullsrc/Unluau/Lifter/Expressions/NameIndex.cs- Check Expression for nullsrc/Unluau/Lifter/Statements/LocalAssignment.cs- Check Expression and Value for nullsrc/Unluau/Lifter/Statements/Assignment.cs- Check Variable and Value for nullsrc/Unluau/Lifter/Expressions/BinaryExpression.cs- Check Left and Right for nullsrc/Unluau/Lifter/Statements/Return.cs- Handle null expressions in listsrc/Unluau/Lifter/Statements/Statement.cs- Check for null statements in sequencesrc/Unluau/Lifter/Expressions/Closure.cs- Check Block for nullResults
Before:
After:
Testing
Tested with 13 real-world Luau bytecode files ranging from 1.5KB to 53KB.
Test files are available in issue #[71].
Notes
The 5 remaining files that don't decompile appear to use bytecode instructions that Unluau doesn't support yet (JUMP, FORNLOOP, etc.), but at least they no longer crash the decompiler.
Fixes #[72]