Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] YAML binary type is mangled #761

Open
Maia-Everett opened this issue Apr 20, 2024 · 0 comments
Open

[BUG] YAML binary type is mangled #761

Maia-Everett opened this issue Apr 20, 2024 · 0 comments

Comments

@Maia-Everett
Copy link

Maia-Everett commented Apr 20, 2024

YAML supports the !!binary syntax for declaring binary values, which is supported by js-yaml and is parsed as Uint8Array values, but config mangles them by turning them into objects.

For a minimal example, see:

https://codeberg.org/Linneris/config-yaml-binary-bug

Run:

npm install
npm start

Expected output

Expected secret: Uint8Array(6) [ 0, 1, 2, 3, 4, 5 ]
Actual secret: Uint8Array(6) [ 0, 1, 2, 3, 4, 5 ]
Buffer equality: true

Actual output

Expected secret: Uint8Array(6) [ 0, 1, 2, 3, 4, 5 ]
Actual secret: Uint8Array { '0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5 }
node:buffer:535
  if (obj.length !== undefined || isAnyArrayBuffer(obj.buffer)) {
          ^

TypeError: Method get TypedArray.prototype.length called on incompatible receiver [object Object]
    at get length (<anonymous>)
    at fromObject (node:buffer:535:11)
    at Function.from (node:buffer:312:15)
    at file:///[dir]/config-yaml-binary-bug/src/index.js:10:29
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async loadESM (node:internal/process/esm_loader:28:7)
    at async handleMainPromise (node:internal/modules/run_main:113:12)

Please tell us about your environment:

  • node-config version: 3.3.11
  • node-version: 20.11.00
  • js-yaml version: 4.1.0

Edit: One way to fix this without breaking immutability would be to convert typed arrays to regular arrays with Array.from(), then freeze them. But since Buffer instances are already returned unmodified, perhaps the simplest fix would be to add

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

No branches or pull requests

1 participant