Skip to content

fix(buffer): support latin1/ascii/base64url encodings and honor concat totalLength - #1864

Merged
richarddd merged 2 commits into
awslabs:mainfrom
arxhr007:fix/buffer-encodings
Nov 4, 2026
Merged

richarddd merged 2 commits into
awslabs:mainfrom
arxhr007:fix/buffer-encodings

Conversation

@arxhr007

@arxhr007 arxhr007 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Issue # (if available)

None — found via differential fuzzing of Buffer encoding and concat behavior against Node.js.

Description of changes

  • latin1, binary, ascii and base64url encodings. Buffer.from(str, "latin1") decoded the string as UTF-8 (e.g. "café" produced 5 bytes instead of 4), and base64url was rejected entirely. New Latin1 and Base64Url Encoder variants decode/encode one byte per code unit and accept the URL-safe alphabet without padding. ascii decodes masked to 7 bits and encodes like latin1, matching Node's behavior.
  • Buffer.isEncoding now accepts exactly the labels Node accepts (e.g. iso-8859-1 and windows-1252 are rejected; buffer is kept as the existing LLRT alias).
  • Buffer.concat(list, totalLength) ignored the remainder of totalLength and returned a short buffer; it now zero-pads like Node.
  • Blob part number formatting uses ryu-js to match ToString semantics.

Checklist

  • Created unit tests in tests/unit and/or in Rust for my feature if needed
  • Ran make fix to format JS and apply Clippy auto fixes
  • Made sure my code didn't add any additional warnings: make check
  • Added relevant type info in types/ directory (no signature changes)
  • Updated documentation if needed (API.md/README.md/Other) (not needed)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…t totalLength

- Buffer.from/toString accepted 'latin1', 'binary', 'ascii' and
  'base64url' labels were either rejected or decoded as UTF-8. Node
  decodes latin1/binary/ascii as one byte per code unit and accepts
  base64url without padding.
- Add Latin1 and Base64Url encoder variants; 'ascii' decodes masked to
  7 bits and encodes like latin1, matching Node.
- Buffer.isEncoding now accepts exactly Node's label set.
- Buffer.concat(list, totalLength) ignored the remainder of
  totalLength and returned a short buffer; it now zero-pads like Node.
- Blob part number formatting uses ryu-js to match JS ToString.

@richarddd richarddd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comment. Also do we use from_str and for_buffer now? this can be confusing

Comment thread modules/llrt_buffer/Cargo.toml Resolved
Review feedback: pin the ryu-js version like other workspace deps, and
disambiguate the two encoding constructors — from_label (WHATWG
Encoding Standard labels, TextDecoder semantics) vs for_buffer (Node.js
Buffer encodings).
@arxhr007

arxhr007 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Done — pinned ryu-js to "1" and renamed the WHATWG constructor to from_label/from_label_optional so the two entry points read unambiguously: from_label (WHATWG Encoding Standard labels) vs for_buffer (Node.js Buffer encodings).

@richarddd
richarddd merged commit 7e0d003 into awslabs:main Nov 4, 2026
32 checks passed
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.

2 participants