console.log/info/warn/error/debug silently truncate the line at an embedded NUL (U+0000)

Đang mở Phù hợp với người mới
#359 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp, wasm
Lĩnh vực
backend, devtools

Hướng nghiên cứu

Bắt đầu với builtins/web/console.cpp và theo dõi cách console_out chuyển dòng đã định dạng đến builtin_impl_console_log; sau đó kiểm tra các phương thức console khác và phần ghi đè của ComponentizeJS trong embedding/embedding.cpp. Giữ nguyên toàn bộ chuỗi, bao gồm cả các NUL được nhúng, xuyên suốt hook và đường xuất dữ liệu. Xác nhận rằng bản tái hiện in ra toàn bộ nội dung sau NUL cho từng phương thức bị ảnh hưởng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

If any argument to a console method contains U+0000, everything after it on that line is lost, including later
arguments. No error is raised. JS strings may contain U+0000 (for example, output from TextDecoder, binary
protocols or String.fromCharCode loops), so debug output silently drops data.

Environment

  • StarlingMonkey v0.4.0 release starling.wasm, wasmtime 50.0.1, --legacy-script.
  • The code involved is unchanged on main (54b3329b).
  • Also seen in a @bytecodealliance/componentize-js 0.23.0 component.
  • Checked on 2026-11-03. Reference: node v26.13.0.

Reproduction

console.log("a\u0000b", "c");
console.log("x", "a\u0000b", "c");
console.error(["a\u0000b"]);
console.log("next line is fine");
StarlingMonkey node
line 1 Log: a a\0b c
line 2 Log: x a x a\0b c
line 3 Error: [ "a [ 'a\x00b' ]
line 4 Log: next line is fine next line is fine

Expected

The whole line is printed (with the NUL written as-is or escaped). The Console Standard
leaves the output format to the implementation, but nothing allows dropping part of the data.

Cause

console_out in builtins/web/console.cpp builds the complete line in a std::string (NULs included), then calls

builtin_impl_console_log(log_ty, fullLogLine.c_str());

and builtin_impl_console_log(Console::LogType, const char *msg) prints msg as a C string, which stops at the first
'\0'. The other console methods (assert, count, time*, group, trace) pass .c_str() the same way.

Suggested fix

Change the hook to take a length-carrying string, e.g. builtin_impl_console_log(Console::LogType, std::string_view msg),
and print it with std::println(stdout, "{}: {}", prefix, msg) (a string_view argument keeps embedded NULs) or
fwrite(msg.data(), 1, msg.size(), stdout). Since builtin_impl_console_log is a weak symbol that embedders override,
ComponentizeJS's override in embedding/embedding.cpp (which prints with fprintf(stdout, "%s\n", msg)) needs the same
signature change.

Ngôn ngữ chính
C
Star
297
Fork
64
Merge trung bình
1 ngày 17 giờ
Pull request đã merge (30 ngày)
16

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của bytecodealliance/StarlingMonkey

Tất cả issue của bytecodealliance/StarlingMonkey

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.