Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[BUG] YAML binary type is mangled #761

@Maia-Everett

Description

@Maia-Everett

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions