Bug/Crash: Toolbar buffer overflow (Assertion failed) on wide terminal windows:
Describe the bug
When connecting to the Bus Pirate via a wide terminal emulator window (e.g., >200 columns), the device crashes, the USB connection drops, and dmesg shows enumeration errors (error -71).
I debugged this using a hardware probe (via OpenOCD/GDB in VS Code) and traced the crash to a hard assertion in tx_tb_start() inside src/usb_tx.c.
Root Cause Analysis
In src/usb_tx.c, the toolbar buffer limit is defined as 1024:
#define MAXIMUM_TOOLBAR_BUFFER_BYTES 1024
However, when rendering the toolbar for a wide terminal (system_config.terminal_ansi_columns was 209 in my case), the combination of the text, ANSI color codes, and cursor hide/show escape sequences easily exceeds this limit.
During my GDB session, I caught the exact state right before the crash:
width= 209buf_len= 1024lenreached 1032 insidetoolbar_core1_service()(src/ui/ui_toolbar.c).
Because len (1032) > MAXIMUM_TOOLBAR_BUFFER_BYTES (1024), the following assertion is triggered, causing a panic on Core 1 and dropping the USB connection:
BP_ASSERT(len <= MAXIMUM_TOOLBAR_BUFFER_BYTES);
Steps to reproduce
- Connect Bus Pirate to the PC.
- Open a terminal emulator (i used tio) and maximize the window on a wide monitor (so terminal columns exceed ~200).
- The device attempts to render the bottom toolbar, hits the buffer limit, asserts, and crashes (USB disconnects).
Proposed Fix
The simplest fix is to increase the buffer size in src/usb_tx.c to accommodate modern wide displays.
Changing:
#define MAXIMUM_TOOLBAR_BUFFER_BYTES 1024
to:
#define MAXIMUM_TOOLBAR_BUFFER_BYTES 2048 (or 4096)
completely resolved the issue for me.
Alternatively, the rendering logic in toolbar_core1_service() could be modified to truncate the output if len approaches buf_len, preventing the overflow gracefully.
Environment
- Hardware: RP2350 (Bus Pirate 6 / Custom Board)
- Firmware: Main branch (latest)
- OS: Linux (Ubuntu)
Issue opened by: reza-bakhshi