Skip to content

fix(language): use PyLong_AsSize_t for pointer-sized language IDs#470

Merged
ObserverOfTime merged 1 commit into
tree-sitter:masterfrom
A-S-Manoj:fix/language-init-overflow
Jul 7, 2026
Merged

fix(language): use PyLong_AsSize_t for pointer-sized language IDs#470
ObserverOfTime merged 1 commit into
tree-sitter:masterfrom
A-S-Manoj:fix/language-init-overflow

Conversation

@A-S-Manoj

Copy link
Copy Markdown
Contributor

Fixes #469.
PyLong_AsUnsignedLong was introduced in 14e7893 for a value that's actually a pointer (Py_uintptr_t). On 64-bit Windows (LLP64), unsigned long is 32-bit while pointers are 64-bit, so this overflows for any real pointer value passed to the deprecated int-based Language() constructor — exactly the OverflowError reported in the issue.
Reverted that one call to PyLong_AsSize_t, which is pointer-width on all platforms (including Win64), matching the pre-refactor behavior. This doesn't affect the other unsigned long conversions from that commit, since those hold 32-bit byte offsets/counts, not pointers.

 PyLong_AsUnsignedLong truncates on Win64 (LLP64), where unsigned long is 32-bit but pointers are 64-bit, causing OverflowError when constructing a Language from a raw pointer int. Fixes tree-sitter#469
@A-S-Manoj

Copy link
Copy Markdown
Contributor Author

The one failing check (test_hash in tests/test_node.py) looks unrelated to this change — this PR only touches PyLong_AsSize_t for pointer-sized Language IDs, not Node.hash.

@ObserverOfTime ObserverOfTime merged commit 41c761b into tree-sitter:master Jul 7, 2026
57 of 58 checks passed
@ObserverOfTime

Copy link
Copy Markdown
Member

Thanks!

@A-S-Manoj

Copy link
Copy Markdown
Contributor Author

You're very welcome! I'm glad I could help, and I look forward to tackling more issues

@A-S-Manoj A-S-Manoj deleted the fix/language-init-overflow branch July 8, 2026 02:59
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.

OverflowError: Python int too large to convert to C unsigned long

2 participants