Skip to content

Commit 8c1677a

Browse files
fix(fwt): fix vlq max length calculation
The VLQ max length calculation was incorrect, leading to insufficient buffer allocation for the token. This commit corrects the calculation and updates the tests to include a test case for max-uint64.
1 parent 095d51f commit 8c1677a

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

fwt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func (s *Signer) Sign(data any) (string, error) {
133133
}
134134

135135
// allocate token type + VLQ Max Length + marshaled length + signature length
136-
token := memory.Alloc(1 + 9 + len(marshaled) + len(signature))
136+
token := memory.Alloc(1 + 10 + len(marshaled) + len(signature))
137137
token[0] = byte(s.signatureType)
138138

139139
vlqLength, err := encodeVLQ(token[1:], uint64(len(marshaled)))

vlq_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func TestVLQEncodeDecode(t *testing.T) {
2424
{"two-bytes-max", 16384, 2, false, 2},
2525
{"large-value", 1234567890, 5, false, 5},
2626
{"max-uint32", uint64(^uint32(0)), 5, false, 5},
27+
{"max-uint64", ^uint64(0), 10, false, 10},
2728
}
2829

2930
for _, tt := range tests {

0 commit comments

Comments
 (0)