Skip to content

Lockdown Compat: Hardened TextDecoder instance with nodejs fast path (eg ascii encoding) #2813

@kumavis

Description

@kumavis

Describe the bug

Seems like a nodejs + override mistake compat issue.
When using a hardened textDecoder with ascii encoding, there is an error on certain platforms.

harden(new TextDecoder('ascii', { fatal: true }))

Cannot assign to read only property 'Symbol(kLatin1FastPath)' of object '[object TextDecoder]'

Steps to reproduce

  1. lockdown
  2. make textDecoder with 'ascii' encoding.
  3. harden the textDecoder
  4. decode text buffer
lockdown()
t = harden(new TextDecoder('ascii', { fatal: true }))
t.decode(Buffer.from([]))

// SES_UNCAUGHT_EXCEPTION: (TypeError#1)
// TypeError#1: Cannot assign to read only property 'Symbol(kLatin1FastPath)' of object '[object TextDecoder]'

Expected behavior

No error

Platform environment

Nodejs versions checked:

20.18.0 🟢
20.18.2 🟢
20.18.3
20.19.0
20.19.1
20.19.2 ❌ (latest v20)
21.0.0 🟢
21.7.3 🟢 (latest v21)
22.0.0 🟢
22.15.1 ❌ (latest v22)
24.0.0
24.0.2 ❌ (latest v24)

Additional context

https://github.com/nodejs/node/blob/b395420a99fff9e59256a66437762cbdacd44cb7/lib/internal/encoding.js#L424

Attempted a workaround by warming up the textDecoder (decoding once) before harden, but harden still broke further use of the text decoder

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingecosystem-compatibilityTracks a compatibility issue in a third-party package or packages.taming compat

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions