Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#98 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
1-2 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
cpp
Área
backend, mobile

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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)
Lenguaje dominante
C++
Estrellas
27
Forks
4
Merge medio
16 h 48 min
PR fusionados (30 d)
4

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de NativeScript/runtimes

Todos los issues de NativeScript/runtimes

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.