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

オープン 初心者向け
#359 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp, wasm
領域
backend, devtools

調査の方向性

builtins/web/console.cppから始め、console_outがフォーマット済みの行をbuiltin_impl_console_logに渡す方法をたどります。次に、他のコンソールメソッドとembedding/embedding.cppにあるComponentizeJSのオーバーライドを確認します。埋め込みNULを含む文字列全体を、フックと出力経路を通じて保持します。再現コードで、影響を受ける各メソッドについてNUL以降の内容がすべて出力されることを確認します。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C
スター
297
フォーク
64
平均マージ
2日 2時間
マージ済み PR(30日)
19

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bytecodealliance/StarlingMonkey のほかの issue

bytecodealliance/StarlingMonkey の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。