Skip to content

Fix UBJSON parser crashes with unknown types (Issue #57)#58

Open
zarfld wants to merge 2 commits into
featherbear:masterfrom
zarfld:fix/ubjson-type-recovery-issue-57
Open

Fix UBJSON parser crashes with unknown types (Issue #57)#58
zarfld wants to merge 2 commits into
featherbear:masterfrom
zarfld:fix/ubjson-type-recovery-issue-57

Conversation

@zarfld

@zarfld zarfld commented Nov 3, 2025

Copy link
Copy Markdown

Problem 🐛

Node.js process crashes when connecting to StudioLive 32SC mixers due to unknown UBJSON types (type 73, type 114, etc.) in the data stream. This affects newer PreSonus firmware and makes the API unsuitable for production mixer control systems.

Before Fix:

  • ❌ Process crashes immediately on unknown types
  • ❌ Complete connection loss to mixer
  • ❌ No error recovery or graceful degradation
  • ❌ Applications terminate without warning

Solution ✅

Comprehensive error recovery system that prevents crashes while maintaining functionality:

Key Improvements:

  • 🛡️ Graceful Error Handling: Unknown types no longer crash the process
  • 🔄 Recovery Mechanisms: Advanced buffer scanning and workingSet validation
  • 📊 Analysis Logging: Detailed error analysis for debugging unknown types
  • ⚡ Maintained Performance: Existing functionality unaffected
  • 🔍 Type Extensions: Support for PreSonus UBJSON extensions (types 73, 114)

Files Changed:

  1. src/lib/util/zlib/ubjson.ts - Complete error recovery system
  2. src/lib/util/zlib/zlibUtil.ts - Payload validation and error indicators
  3. src/lib/packetParser/ZB.ts - Packet-level error protection

Testing 🧪

Hardware Validated:

  • Mixer: StudioLive 32SC at 157.247.3.12:53000
  • Firmware: 3.2.0.108461 (contains problematic type 73)
  • Node.js: v22.20.0
  • Duration: Multi-hour stability testing

Results:

  • ✅ Process remains stable with unknown types
  • ✅ Detailed error logging without crashes
  • ✅ Mixer control functionality preserved
  • ✅ Graceful degradation for unparsable data
  • ✅ Analysis data saved for further investigation

Test Output:

🔧 UBJSON: Unknown type 73 (0x49) at position 27415, attempting recovery
🔧 Type 73 (I): using length 4 from position 27416  
🔧 Type 73 (I) parsed as int32: 1023 (hex: 000003ff)
✅ Bridge remains stable - no crashes

Impact Assessment 📈

Production Benefits:

  • 🎯 Stability: Eliminates crashes for StudioLive 32SC users
  • 🚀 Reliability: Enables stable production mixer control applications
  • 🔧 Maintainability: Clear error logging aids debugging
  • 📦 Compatibility: Backwards compatible with existing mixers
  • 🔄 Future-Proof: Handles new PreSonus protocol extensions

Before vs After:

Aspect Before After
Unknown Types Process crash Graceful handling
Error Recovery None Advanced scanning
Debugging No info Detailed analysis
Stability Unreliable Production-ready
Compatibility Limited Broad firmware support

Technical Details 🔧

Error Recovery Strategy:

  1. Try-Catch Protection: Wrap parsing with comprehensive error handling
  2. Buffer Scanning: Smart recovery by finding next valid structures
  3. WorkingSet Validation: Ensure parser state integrity
  4. Analysis Logging: Save problematic data for investigation
  5. Graceful Degradation: Continue parsing with partial data

PreSonus Extensions Handled:

  • Type 73 (0x49 'I'): Variable length data with length prefix
  • Type 114 (0x72 'r'): String-like data with length prefix
  • Future Types: Framework ready for additional extensions

Related Issues 🔗

Fixes #57 - UBJSON Parser Error: Unknown type 73 crashes Node.js process on StudioLive 32SC

Pattern Recognition:

  • Addresses recurring UBJSON parsing issues in PreSonus ecosystem
  • Related to Issue Error: Unknown type 85 at position 27255 #50 (type 85) - same root cause, different type
  • Establishes framework for handling future firmware extensions

Community Impact 🌟

This fix enables:

  • Stable mixer control applications for live audio environments
  • Development of production-grade PreSonus integrations
  • Support for newer firmware without breaking existing functionality
  • Foundation for future protocol extensions and types
  • Improved developer experience with detailed error information

Request for Review 👀

@featherbear - This implements the graceful error handling approach discussed in the issue. The solution:

  1. Prevents crashes while maintaining full existing functionality
  2. Provides detailed logging to help understand unknown types
  3. Establishes framework for supporting future PreSonus extensions
  4. Maintains backwards compatibility with all existing mixers
  5. Enables production deployment on newer firmware versions

Would appreciate feedback on the implementation approach and any suggestions for further improvements!


Testing Environment:

  • Date: November 3, 2025
  • API Version: v1.7.2
  • Node.js: v22.20.0
  • Platform: Windows
  • Network: Local StudioLive mixer environment

- Add comprehensive error recovery for unknown UBJSON types 73, 114, etc.
- Prevent Node.js process crashes with graceful degradation
- Enhanced buffer validation and recovery mechanisms  
- Improved workingSet integrity validation
- Added robust recovery scanning for corrupted data streams
- Maintain parsing functionality while handling PreSonus extensions
- Comprehensive error analysis and debug logging
- Tested with StudioLive 32SC firmware 3.2.0.108461

Changes:
- ubjson.ts: Complete error recovery system with analysis logging
- zlibUtil.ts: Null payload validation and error indicators  
- ZB.ts: Graceful packet handling with try-catch protection

This allows stable mixer control applications on newer PreSonus firmware
while maintaining backwards compatibility with existing functionality.
@featherbear

featherbear commented Nov 15, 2025

Copy link
Copy Markdown
Owner

I think there's too many changes in this one PR, it's deviated from the required change.
Also there's some anti-patterns introduced, a network API shouldn't be writing files to the disk; it will cause crashes at t=∞

…ery logic\n- Revert try/catch wrappers in ZB/zlibUtil\n- Keep minimal UBJSON extensions: 0x49 (I), 0x72 (r)\n- Preserve original int64 BigInt behavior
}

// PreSonus extension: type 114 (0x72 = 'r') - string type
case 0x72 /* r */: {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Do you have an example property which uses this type?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Need to check. That was some time ago so i dint remember exactly. But i think i can get examples for reference

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.

UBJSON Parser Error: Unknown type 73 crashes Node.js process on StudioLive 32SC

2 participants