Skip to content

Avoid a crash in reflected tree division - #1511

Open
khushalx wants to merge 1 commit into
libgit2:masterfrom
khushalx:codex/tree-reflected-division
Open

khushalx wants to merge 1 commit into
libgit2:masterfrom
khushalx:codex/tree-reflected-division

Conversation

@khushalx

@khushalx khushalx commented Dec 1, 2026

Copy link
Copy Markdown

Fixes #1505.

Python can call the tree division slot for reflected division, with a non-tree object as the left operand. Tree_divide currently reads that object as a tree and segfaults.

Check the left operand before loading tree data and return NotImplemented when it is not a tree. Python then raises the usual TypeError. Regression tests cover integer, float, None, and string left operands; existing tests cover normal tree path lookup.

Validation on macOS arm64, Python 3.12.16, libgit2 1.9.7:

  • The new regression crashes the original extension with SIGSEGV (exit code -11).
  • Full suite after rebuilding: 673 passed, 14 skipped, 1 xpassed. The skips are platform, TLS, SSH, proxy, and config dependent; the xpass is the existing macOS index-conflict test.
  • Mypy, stubtest, Ruff lint, Ruff formatting, and git diff --check pass.

AI assistance: OpenAI Codex helped investigate, implement, and test the fix.

Return NotImplemented for reflected division with a non-tree left operand instead of treating it as a tree and crashing.

Fixes libgit2#1505

Assisted-by: GPT-6 (Codex)
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.

Tree.__truediv__ assumes its first operand is a Tree, so 0 / tree leads to seg fault

1 participant