Skip to content

Fix multiple NullReferenceException issues - doubles success rate to 62%#72

Merged
atrexus merged 2 commits into
atrexus:mainfrom
piplarsson:main
Aug 18, 2025
Merged

Fix multiple NullReferenceException issues - doubles success rate to 62%#72
atrexus merged 2 commits into
atrexus:mainfrom
piplarsson:main

Conversation

@piplarsson

@piplarsson piplarsson commented Aug 17, 2025

Copy link
Copy Markdown
Contributor

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 #[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]

## 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%
@atrexus atrexus merged commit f89e03a into atrexus:main Aug 18, 2025
1 check failed
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