TextDecoder: ERR_ENCODING_INVALID_ENCODED_DATA on very long array buffer
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 122k
- Fork
- 37.3k
- Merge trung bình
- 4 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 283
Mô tả
Version
v18.14.1
Platform
Linux 5.19.0-38-generic #39~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 17 21:16:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
When I try to decode a long utf-16le encoded buffer, ERR_ENCODING_INVALID_ENCODED_DATA is thrown instead of ERR_STRING_TOO_LONG.
new TextDecoder("utf-16le").decode(new Uint16Array(2**27).fill(48))
// Uncaught TypeError: The encoded data was not valid for encoding utf-16le
// at TextDecoder.decode (node:internal/encoding:448:14) {
// code: 'ERR_ENCODING_INVALID_ENCODED_DATA'
// }
The default encoding version seems to work correctly, and throws an appropriate error
new TextDecoder().decode(new Uint8Array(2**29).fill(48))
// Uncaught Error: Cannot create a string longer than 0x1fffffe8 characters
// at TextDecoder.decode (node:internal/encoding:433:16) {
// code: 'ERR_STRING_TOO_LONG'
// }
Another thing that I realized is that TextDecoder() seems to be capable of consuming an array buffer twice as long as TextDecoder("utf-16le") without throwing error, and produce a string that's 4 times as long.
How often does it reproduce? Is there a required condition?
Confirmed this bug in both normal file execution and node.js repl
What is the expected behavior? Why is that the expected behavior?
new TextDecoder("utf-16le") should be able to create a string up to 0x1fffffe8 characters.
It should throw ERR_STRING_TOO_LONG when this length is exceeded.
What do you see instead?
ERR_ENCODING_INVALID_ENCODED_DATA is thrown when the input Uint16Array length is 2**27
Uncaught TypeError: The encoded data was not valid for encoding utf-16le
at TextDecoder.decode (node:internal/encoding:448:14) {
code: 'ERR_ENCODING_INVALID_ENCODED_DATA'
}
Additional information
No response
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với đường dẫn TextDecoder.decode được hiển thị tại node:internal/encoding:448 và so sánh nó với đường dẫn decoder mặc định tại node:internal/encoding:433. Tái hiện trường hợp utf-16le bằng đầu vào Uint16Array được cung cấp, sau đó xác minh rằng đầu ra đã giải mã quá lớn báo cáo ERR_STRING_TOO_LONG thay vì ERR_ENCODING_INVALID_ENCODED_DATA.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, node.js
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 55/100