Fix byte offset bugs when working with Uint8Array subarrays - #62
Merged
lbaquerofierro merged 1 commit intoFeb 11, 2026
Merged
Conversation
When using Uint8Array.subarray(), the .buffer property still points to the original ArrayBuffer, not just the slice. This was causing issues in two places: 1. DataView constructors weren't accounting for byteOffset when parsing subarrays 2. serialize() methods were using .buffer directly, which included extra bytes Added proper byteOffset/byteLength handling to DataView calls and buffer.slice() in serialize methods. Also fixed tokenEntryToSerializedLength() which was missing the 3 byte header (token_type + truncated_token_key_id) in its calculation. Verified working with privacypass-issuer (all 35 tests pass).
lbaquerofierro
requested review from
armfazh and
thibmeu
and removed request for
thibmeu
February 10, 2026 21:45
armfazh
reviewed
Feb 10, 2026
| switch (tokenType.value) { | ||
| case TOKEN_TYPES.VOPRF.value: | ||
| return VOPRF.Ne + 2 * VOPRF.Nk; | ||
| return headerLen + VOPRF.Ne; |
Contributor
There was a problem hiding this comment.
I think the blinded_msg size is Ne
Contributor
Author
There was a problem hiding this comment.
Yes, exactly. For VOPRF the blinded_msg is Ne bytes per Section 5.1 of the spec (v16). The fix adds the 3 byte header (token_type + truncated_token_key_id) that was missing from the original calculation
Contributor
There was a problem hiding this comment.
let's add this test in this line:
https://github.com/cloudflare/privacypass-ts/blob/main/test/generic_batched_token.test.ts#L134
// check BatchedTokenRequest deserialization.
const token_request_bytes = hexToUint8(v.token_request);
const tokReqGot = BatchedTokenRequest.deserialize(token_request_bytes);
expect(tokReq.tokenRequests.length).toBe(tokReqGot.tokenRequests.length);
for (let i = 0; i < tokReq.tokenRequests.length; i += 1) {
expect(tokReq.tokenRequests[i].tokenType).toBe(tokReqGot.tokenRequests[i].tokenType);
expect(tokReq.tokenRequests[i].truncatedTokenKeyId).toBe(
tokReqGot.tokenRequests[i].truncatedTokenKeyId,
);
expect(tokReq.tokenRequests[i].blindMsg).toStrictEqual(
tokReqGot.tokenRequests[i].blindMsg,
);
}
armfazh
suggested changes
Feb 10, 2026
armfazh
left a comment
Contributor
There was a problem hiding this comment.
it works, let's add a test for BatchedTokenRequest.deserialize, see my comment above
armfazh
approved these changes
Feb 11, 2026
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
When using
Uint8Array.subarray(), the.bufferproperty still points to the original ArrayBuffer, not just the slice. This was causing issues in two places:.bufferdirectly, which included extra bytesChanges
(bytes.buffer, bytes.byteOffset, bytes.byteLength)buffer.slice(byteOffset, byteOffset + byteLength)tokenEntryToSerializedLength()which was missing the 3 byte header (token_type + truncated_token_key_id)Files changed
src/generic_batched_token.tssrc/index.tssrc/priv_verif_token.tssrc/pub_verif_token.tsTesting