Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Android napi: console.time / console.timeEnd dereference a missing map entry

オープン
#98 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

評価

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

調査の方向性

Start with NativeScript/runtime/android/napi/modules/console/Console.cpp and compare the napi console creation and callbacks with createConsole() in the jsi tree. Reproduce with console.time("x"); console.timeEnd("x"); on a napi engine, then check that per-environment timer state is initialized, missing entries return safely, and access is synchronized. Done means the repro measures and logs elapsed time without undefined behavior.

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

説明

bug

Summary

On napi, console.time and console.timeEnd dereference a map iterator that is always end(). Console::s_envToConsoleTimersMap (NativeScript/runtime/android/napi/modules/console/Console.cpp) is never given an entry for any napi_env, so:

auto it = Console::s_envToConsoleTimersMap.find(env);
if (it == Console::s_envToConsoleTimersMap.end()) {
    // throw?
}
...
it->second.insert(std::make_pair(label, timeStamp));   // it == end()

timeCallback inserts into it->second with it == end(), which is undefined behaviour. timeEndCallback copies it->second by value and later erases from it, which is undefined for the same reason.

The jsi tree does not have this bug: its createConsole() emplaces an entry per runtime, and its callbacks return early when the entry is missing.

Repro

On any napi engine:

console.time("x");
console.timeEnd("x");

The result depends on the heap layout: anything from nothing visible to a corrupted heap or a crash.

Expected

console.time / console.timeEnd measure and log the elapsed time. Fix: create the per-env entry when the console is created, as jsi does, and bail out if it is missing. The map has the same cross-thread race as the jsi one, so it needs the same synchronization.

Environment

  • Branch: android-react-native at 64c7fed0
  • Binding layer: napi (all engines)
主要言語
C++
スター
27
フォーク
4
平均マージ
16時間 48分
マージ済み PR(30日)
4

環境構築

はじめの一歩

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

NativeScript/runtimes のほかの issue

NativeScript/runtimes の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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