-
Notifications
You must be signed in to change notification settings - Fork 30k
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
RangeError in TextDecoder.decode with QEmu VM #42215
Comments
The simplest way to reproduce this issue is to launch node with the following file : var text_encoder = new TextEncoder("utf-8");
var buffer_utf8 = text_encoder.encode("XXXXXX");
var text_decoder = new TextDecoder("utf-8");
var res= text_decoder.decode(buffer_utf8); Without workaround, it crashes : $ node test.js
buffer.js:605
slice: (buf, start, end) => buf.utf8Slice(start, end),
^
RangeError: Index out of range
at Object.slice (buffer.js:605:37)
at Buffer.toString (buffer.js:802:14)
at Object.readFileSync (fs.js:408:41)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1025:18)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47 {
code: 'ERR_OUT_OF_RANGE'
} With one of the two workarounds, it works : $ ./node test.js
XXXXXX The problematic line is : var res= text_decoder.decode(buffer_utf8); It seams to be a TextDecoder object issue |
Bug seams to be in the following line in start |= 0; When the value of the You can check this by running this script : var start = undefined;
start |= 0;
console.log(`start=${start}`); When I run this script directly on Windows, I get : ./node test.js
start=0 When I run this script in a QEMU VM on Windows, I get -1 : ./node test.js
start=-1 Using the syntax |
Node sometimes hits bugs in qemu, see #33503 for another example. There's not really anything we can do here, your best bet is to report it to the qemu project. |
Yes, I agree : this is a QEmu issue. |
There's probably no minimal test case you can distill out of this. V8 is a JIT compiler, it generates machine code at runtime. That machine code can also self-modify while it's executing. qemu probably fails to pick that up sometimes. I'll go ahead and close this out but let me know if you still have questions. |
Version
16.13.2
Platform
Linux PP01248 5.10.0-9-amd64 #1 SMP Debian 5.10.70-1 (2021-09-30) x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
node crashes at startup when executed in a QEmu VM.
I found two workarounds but I can't figure out why it works. And why it only occurres on a QEmu VM...
First workaround
A first workaround is to force the
start
argument of thetoString
function (filelib/buffer.js
) to zero when it's value is is undefined :Second workaround
Another way to fix bug is to add a similar workaround in the
ParseArrayIndex
function insrc/node_buffer.cc
:How often does it reproduce? Is there a required condition?
This crash occurres every time I start node on a QEmu VM.
What is the expected behavior?
I should have REPL prompt :
What do you see instead?
I have this error :
Additional information
This is not a REPL issue : I got the same crash when I start node with a script (
essai.js
) which contains a simpleconsole.log
line :You can reproduce this error with this code :
The text was updated successfully, but these errors were encountered: