UBSAN: left shifts into the sign bit in unaligned-read helpers

Abierto
#2,445 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

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

Línea de trabajo

Start with the listed shift expressions in src/libAtomVM/bitstring.h, src/libAtomVM/utils.h, src/libAtomVM/opcodesswitch.h, and src/libAtomVM/inet.c; read how each helper builds its integer value. Run the test suite with -fsanitize=undefined to reproduce the reports, then rerun it to confirm they are gone after the shifts are made defined. Done means all listed cases pass without UBSAN reports.

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

Descripción

Running the test suite with -fsanitize=undefined reports "left shift of N by 24 places cannot be represented in type 'int'" (and by 56 places into 'long') from:

  • READ_32LE_UNALIGNED in src/libAtomVM/bitstring.h:45 and READ_32_UNALIGNED in src/libAtomVM/utils.h:57, :85 and :138: ((uint8_t *) ptr)[3] << 24 promotes the byte to int before shifting, so any byte >= 0x80 overflows.
  • large_integer_to_term in src/libAtomVM/opcodesswitch.h:1339 and :1378: ((int32_t) compact_term[0]) << 24 and ((int64_t) compact_term[0]) << 56.
  • src/libAtomVM/inet.c:66: (term_to_int32(...) & 0xFF) << 24.

The generated code does what is intended today, but it is undefined behaviour and a compiler may legitimately miscompile it. Casting each byte to uint32_t/uint64_t before the shift (and converting to the signed type afterwards) fixes all of them.

Lenguaje dominante
Erlang
Estrellas
2.3k
Forks
171
Merge medio
5 d 11 h
PR fusionados (30 d)
19

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 atomvm/AtomVM

Todos los issues de atomvm/AtomVM

Issues similares

Más issues de Backend & API Design

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.