fix(thrift): serialize bigint I64 fields as hex to avoid node-int64 corruption (MESSAGE_NOT_FOUND)#194
Merged
Conversation
…orruption The Thrift writer passed bigint I64 values to the node-int64 constructor as a decimal string (`val.toString()`). node-int64 interprets a bare string as hex, so a message ID like 618946633287860670n was silently truncated to a different value on the wire, causing the LINE server to return MESSAGE_NOT_FOUND / NO_MESSAGE (e.g. talk.react()). Encode the value as a `0x`-prefixed, zero-padded 16-char hex string built from `BigInt.asUintN(64, val)`. This preserves full 64-bit precision for positive values and correctly emits two's-complement bytes for negative I64 values. Adds round-trip and exact-wire-octet regression tests for the Thrift writer. Fixes #193 Co-authored-by: [As]ReMix <remixasoom@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #193.
bigint
I64fields (e.g. a message ID passed totalk.react()) were serialized incorrectly by the Thrift writer. The value was handed to thenode-int64constructor as a decimal string viaval.toString(), butnode-int64interprets a bare string argument as hex. A message ID like618946633287860670nwas therefore truncated to a completely different value on the wire, and the LINE server rejected it withMESSAGE_NOT_FOUND/NO_MESSAGE.Fix
packages/linejs/base/thrift/readwrite/write.tsThis builds a
0x-prefixed, zero-padded 16-char hex string, whichnode-int64parses correctly. UsingBigInt.asUintN(64, val)(rather than the plain"0x" + val.toString(16)from the issue) additionally keeps negativeI64values correct by emitting their full two's-complement bytes instead of zero-extending the low 32 bits.618946633287860670n8946633287860670❌0896f0af040c01be✅-5nfffffffffffffffb✅Tests
Adds
packages/linejs/base/thrift/readwrite/write.test.ts:> Number.MAX_SAFE_INTEGERmessage ID throughwriteThrift/readThrift(binary + compact protocols),Co-authored-by: [As]ReMix remixasoom@gmail.com