Skip to content

Conversation

@przadka
Copy link
Contributor

@przadka przadka commented Dec 3, 2025

Problem

Fixes #1119 - B2 CLI crashes with SystemError: buffer overflow on Python 3.14+ due to a bug in the rst2ansi dependency.

The issue occurs because rst2ansi passes a 4-byte buffer to the TIOCGWINSZ ioctl call, which expects 8 bytes on most platforms. Python 3.14 enforces stricter buffer validation, causing the crash.

Solution

  • Added try-except in b2/_internal/arg_parser.py to catch SystemError and fall back to plain text formatting
  • Added Python 3.14 support to CI matrix, noxfile.py, and pyproject.toml
  • Improved test infrastructure with better pexpect error handling

Test Plan

  • ✅ Added integration test test_help_with_tty that reproduces the issue on Python 3.14
  • ✅ All existing tests pass on Python 3.8-3.14
  • ✅ CI validates the fix works correctly

Upstream Fix

Also submitted upstream fix to rst2ansi: Snaipe/python-rst2ansi#20

The fallback can be removed once rst2ansi is updated.


Submitted from reef-technologies fork after internal review

…upport

This commit addresses issue Backblaze#1119 where B2 CLI crashes with SystemError
on Python 3.14+ due to a buffer overflow bug in the rst2ansi dependency.

Changes:
- Add try-except handler in arg_parser.py to catch SystemError from rst2ansi
- Fall back to plain text formatting when rst2ansi fails
- Add integration test to verify the fix works with real PTY on Python 3.14
- Add dedicated nox session (integration_pty) for PTY tests without xdist
- Add Python 3.14 to noxfile.py, CI matrix, and pyproject.toml

The root cause is in rst2ansi's get_terminal_size() which passes a 4-byte
buffer to TIOCGWINSZ ioctl instead of the required 8 bytes. Python 3.14
enforces stricter buffer validation, triggering the error.

Fixes Backblaze#1119
The PTY test doesn't work properly with pytest-xdist parallelization.
Instead of a dedicated nox session, run it directly in CI on Python 3.14
without xdist to properly test the buffer overflow fix.
The condition needs to be wrapped in ${{ }} for proper evaluation.
The test_help_with_tty test works correctly with pytest-xdist in CI,
so we don't need a separate step. Updated docstring to note that
local execution may not trigger the bug due to environment differences.
Move pexpect wrapper with improved error messages from test_autocomplete
to shared helpers module, and use it in test_help PTY test.
Python 3.14+ emits multiprocessing resource_tracker warnings about
leaked semaphores during test subprocess cleanup. These warnings appear
in stderr and cause test assertions to fail. Filter them out the same
way we already filter DeprecationWarnings.

Fixes integration test failures on Python 3.14.
@olzhasar-reef olzhasar-reef merged commit 60f9673 into Backblaze:master Dec 3, 2025
42 checks passed
@olzhasar-reef olzhasar-reef deleted the fix-buffer-overflow-1119 branch December 3, 2025 18:20
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.

System buffer overflow on MacOS

2 participants