fix(core): prevent TUI buffer overflow panics in dependency view scrollbar rendering #32292
+322
−34
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.
Current Behavior
The TUI dependency view experiences buffer overflow panics when rendering scrollbars on small or constrained terminal sizes. Users encounter crashes with messages like "index outside of buffer" at various coordinates such as (134, 37), (86, 0), (107, 0), etc.
Expected Behavior
The TUI should handle all terminal sizes gracefully without crashing, maintaining proper visual rendering of scrollbars and padding elements while staying within buffer boundaries.
Key Code Changes
The fix adds clean, reusable helper functions for bounds checking to prevent buffer overflows:
1. New Helper Functions (lines 216-239):
2. Simplified Scrollbar Bounds Check (lines 478-481):
3. Cleaner Padding Validation (lines 241-286):
Key improvements:
fits_in_buffer()
andclamp_to_buffer()
can be used throughout the codebaseRelated Issue(s)
This fixes buffer overflow panics that occur when the terminal user interface attempts to render scrollbar widgets and padding outside the available buffer boundaries, particularly on smaller terminal sizes or when the terminal is resized.
The fix adds minimal bounds checking to:
Comprehensive test coverage added: 10 unit tests covering all edge cases including the specific problematic buffer dimensions that previously caused panics (45×30, 76×30, 104×30, 135×37, etc.).
Tested across multiple terminal buffer sizes and confirmed no more buffer overflow panics while maintaining correct scrollbar functionality.