[BUG] ETW Properties::to_vector doubles the result and reads past a string_view

Cerrado Apto para principiantes
#4,347 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@Tyagiquamar ya está trabajando en esto.

Desde el 1/10/2026.

  • #4656 de @Tyagiquamar — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
68/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
cpp

Línea de trabajo

Lea exporters/etw/include/opentelemetry/exporters/etw/etw_properties.h alrededor del generic overload de la línea 84 y del string_view overload de la línea 94; después, inspeccione PropertyVariant::operator= alrededor de la línea 260. Verifique el ETW exporter con un span de string views, asegurándose de que el vector devuelto tenga la misma longitud y preserve el contenido de las views no terminadas en NUL; tenga en cuenta que actualmente ningún trabajo de CI compila ETW.

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

Descripción

needs-triage Stale

Properties::to_vector(span<string_view>) in exporters/etw/include/opentelemetry/exporters/etw/etw_properties.h:94 has two defects on adjacent lines:

std::vector<std::string> static to_vector(const nostd::span<const nostd::string_view> &source)
{
  std::vector<std::string> result(source.size());
  for (const auto &item : source)
  {
    result.push_back(std::string(item.data()));
  }
  return result;
}

The result is twice the size it should be. std::vector<std::string> result(source.size()) value-initialises source.size() empty strings, and the loop then appends source.size() more. A span of three views comes back as six entries whose first three are empty.

std::string(item.data()) reads until a NUL. The function's own comment says the input is a span of "non-owning string views", and nostd::string_view::data() is not required to point at a NUL terminated buffer, so this can read past the view and copy whatever follows it.

The generic overload immediately above, at line 84, is correct and does neither:

template <typename T>
static std::vector<T> to_vector(const nostd::span<const T, nostd::dynamic_extent> &source)
{
  return std::vector<T>(source.begin(), source.end());
}

so the string_view overload looks like a copy that diverged.

It is live code. PropertyVariant::operator= calls it at line 260 for AttributeType::kTypeSpanString, so any ETW span or log record carrying a string-array attribute goes through it.

Why this is a report rather than a pull request

No CI job builds the ETW exporter. WITH_ETW appears in no workflow and in no branch of ci/do_ci.sh; the only workflow that names ETW at all is cppcheck.yml, which analyses rather than compiles. A fix here cannot be verified by the pipeline, and the to_vector change is entangled with the sizing bug rather than being a one line correction, so I would rather not push a blind change into a Windows-only path.

The suggested shape, if a maintainer wants it:

std::vector<std::string> result;
result.reserve(source.size());
for (const auto &item : source)
{
  result.push_back(static_cast<std::string>(item));
}
return result;

nostd::string_view has an explicit operator std::string() that copies by length.

I am happy to send that, but it would be more useful alongside a job that compiles the ETW exporter, since the sizing bug is the kind a single assertion would have caught. Found while sweeping the same string_view::data() shape for #4346, which fixes the four occurrences in components that CI does build.

Lenguaje dominante
C++
Estrellas
1.4k
Forks
660
Merge medio
1 d 12 h
PR fusionados (30 d)
47

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

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 open-telemetry/opentelemetry-cpp

Todos los issues de open-telemetry/opentelemetry-cpp

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.