Skip to content

Python: Serialize large integers as strings in RPC#6829

Merged
knutwannheden merged 1 commit intomainfrom
bright-crab
Feb 26, 2026
Merged

Python: Serialize large integers as strings in RPC#6829
knutwannheden merged 1 commit intomainfrom
bright-crab

Conversation

@knutwannheden
Copy link
Copy Markdown
Contributor

@knutwannheden knutwannheden commented Feb 26, 2026

Summary

Convert Python integers exceeding Java's long range (±2^63) to strings in _get_primitive_value before JSON serialization, avoiding Jackson's StreamReadConstraints.getMaxNumberLength() limit (default 1000 digits).

Context

Python integers have no size limit. When a literal like P = 0xFFFF...FFFF (a 1026-char hex / 1234-digit decimal number) is serialized via _get_primitive_value, it was sent as a raw JSON number. Jackson 2.15+ rejects numbers exceeding 1000 digits, causing deserialization failure. The error was then silently dropped by the JSON-RPC layer (fix in moderneinc/jsonrpc#14), causing the caller to hang indefinitely.

The literal's valueSource field already carries the original hex string, so printing is unaffected by converting the value to a string.

…imits

Jackson 2.15+ rejects JSON numbers exceeding 1000 digits via
StreamReadConstraints.getMaxNumberLength(). Python integers have
no size limit, so a literal like paramiko's 4096-bit DH prime
(1234 decimal digits) was serialized as a raw JSON number, causing
deserialization to fail on the Java side.

Convert integers exceeding Java's long range to strings before
serialization. The original source representation is preserved in
the literal's valueSource field, so printing is unaffected.
@knutwannheden knutwannheden merged commit 19c94ab into main Feb 26, 2026
1 check passed
@knutwannheden knutwannheden deleted the bright-crab branch February 26, 2026 12:54
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant