Skip to content

TextEncoder.encodeInto NOT work on BIG utf8 subarray ON 22.4.1 #62610

@navegador5

Description

@navegador5

Version

Welcome to Node.js v22.4.1

Platform

Linux dev 6.8.0-88-generic #89-Ubuntu SMP PREEMPT_DYNAMIC Sat Oct 11 01:02:46 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

`
const _TE = new TextEncoder();
var s = "aÿ我𝑒"
var u8a = new Uint8Array(2429682061);
var offset = 38928786 ;
_TE.encodeInto(s,u8a.subarray(offset)) // { read: 0, written: 0 } failed
_TE.encodeInto(s,u8a.subarray(offset,offset+10)) //{ read: 5, written: 10 } success

Welcome to Node.js v22.4.1.
Type ".help" for more information.

const _TE = new TextEncoder();
undefined
var s = "aÿ我𝑒"
undefined
var u8a = new Uint8Array(2429682061);
undefined
var offset = 38928786 ;
undefined
_TE.encodeInto(s,u8a.subarray(offset)) // { read: 0, written: 0 } failed
{ read: 0, written: 0 }
_TE.encodeInto(s,u8a.subarray(offset,offset+10)) //{ read: 5, written: 10 } success
{ read: 5, written: 10 }

Welcome to Node.js v24.14.0.
Type ".help" for more information.

const _TE = new TextEncoder();
undefined
var s = "aÿ我𝑒"
undefined
var u8a = new Uint8Array(2429682061);
undefined
var offset = 38928786 ;
undefined
_TE.encodeInto(s,u8a.subarray(offset)) // { read: 0, written: 0 } success
{ read: 5, written: 10 }
_TE.encodeInto(s,u8a.subarray(offset,offset+10)) //{ read: 5, written: 10 } success
{ read: 5, written: 10 }

`

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

alaways in 22.4.1

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

same as 24.14.0

What do you see instead?

const _TE = new TextEncoder();
var s = "aÿ我𝑒"
var u8a = new Uint8Array(2429682061);
var offset = 38928786 ;
_TE.encodeInto(s,u8a.subarray(offset)) // 【{ read: 0, written: 0 } failed】
_TE.encodeInto(s,u8a.subarray(offset,offset+10)) //{ read: 5, written: 10 } success

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    encodingIssues and PRs related to the TextEncoder and TextDecoder APIs.v20.xIssues that can be reproduced on v20.x or PRs targeting the v20.x-staging branch.v22.xIssues that can be reproduced on v22.x or PRs targeting the v22.x-staging branch.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions