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

WASM crashes on Node v22.2.0 if it reaches the new Buffer() deprecation warning #53075

Open
pimterry opened this issue May 20, 2024 · 3 comments · May be fixed by #53089
Open

WASM crashes on Node v22.2.0 if it reaches the new Buffer() deprecation warning #53075

pimterry opened this issue May 20, 2024 · 3 comments · May be fixed by #53089
Labels
buffer Issues and PRs related to the buffer subsystem. util Issues and PRs related to the built-in util module.

Comments

@pimterry
Copy link
Member

Version

v22.2.0

Platform

Any platform

Subsystem

buffer

What steps will reproduce the bug?

Reproducing this requires code that uses new Buffer() with wasm in the stacktrace somewhere.

I ran into this using zstd-codec which calls new Buffer() internally in various places. This can be reproduced with:

  • npm install zstd-codec
  • Run code using the wasm implementation, e.g:
    require('zstd-codec').ZstdCodec.run(zstd => { new zstd.Simple().compress(Buffer.from([])) })

How often does it reproduce? Is there a required condition?

Fails every time with:

Uncaught TypeError: Cannot read properties of undefined (reading '0')
    at isInsideNodeModules (node:internal/util:511:17)
    at showFlaggedDeprecation (node:buffer:178:8)
    at new Buffer (node:buffer:266:3)
    at emval_allocator_3 (eval at craftEmvalAllocator (/tmp/tmp.ujfY2uo6b7/node_modules/zstd-codec/lib/zstd-codec-binding-wasm.js:8:951735), <anonymous>:13:11)
    at __emval_new (/tmp/tmp.ujfY2uo6b7/node_modules/zstd-codec/lib/zstd-codec-binding-wasm.js:8:952078)
    at wasm://wasm/0025c056:wasm-function[50]:0x10d2
    at wasm://wasm/0025c056:wasm-function[87]:0x23c1

What is the expected behavior? Why is that the expected behavior?

This should not fail (and does not, for Node < 22.2.0). In Node v22.1.0 the code snippet above just runs happily without errors.

(Of course, libraries should also update and avoid using deprecated APIs, but it would be good if the deprecation warning itself didn't break anything in the meantime)

What do you see instead?

Fails every time

Additional information

I'm fairly sure that this is due to #52147 (cc @Uzlopak) which changed isInsideNodeModules to check filename[0] for every stack frame.

I'm not really familiar with wasm internals at all, but based on this error I think it looks pretty clear that filename === undefined for wasm stack frames, and so filename[0] crashes for any wasm code that calls that method.

@pimterry pimterry added buffer Issues and PRs related to the buffer subsystem. util Issues and PRs related to the built-in util module. labels May 20, 2024
@Uzlopak
Copy link
Contributor

Uzlopak commented May 20, 2024

This assessment makes sense. It also means that the method getFileName of a stackFrame, returns undefined. So we need to modify it to also check if filename is not undefined.

@Uzlopak
Copy link
Contributor

Uzlopak commented May 21, 2024

@pimterry

Provided PR #53089

@Gudahtt
Copy link

Gudahtt commented Jun 26, 2024

This bug is now affecting v20.15.0 as well (#52147 was included in v20.15.0)

RandomByte added a commit to SAP/ui5-builder that referenced this issue Jul 2, 2024
Replacing deprecated 'new Buffer(string)' with 'Buffer.from(string)'.

Resolves a TypeError being thrown in our tests when executed with
Node 20.15.0 or 22.3.0.

Root cause: nodejs/node#53075
RandomByte added a commit to SAP/ui5-builder that referenced this issue Jul 2, 2024
Replacing deprecated 'new Buffer(string)' with 'Buffer.from(string)'.

Resolves a TypeError being thrown in our tests when executed with
Node 20.15.0 or 22.3.0.

Root cause: nodejs/node#53075
pimterry added a commit to httptoolkit/mockttp that referenced this issue Jul 3, 2024
nodejs/node#53075 results in crashes in test
suite (not in cases relevant to most users) when using the latest Node
v20 or v22, due to Buffer usage deep in wasm within zstd-codc
subdependencies, which are challenging to resolve.

For now, we just skip testing on the latest versions until this is
resolved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants