dropbox / dropbox/rust-alloc-no-stdlib

Soundness/documentation issue: CallocBackingStore::new is not safety documented and potentially unsound

Abierto
#20 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Rust
Estrellas
180
Forks
21
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

The unsafe function CallocBackingStore::new does not have documentation for its safety invariants - and neither does the `define_allocator_memory_pool` macro calling it.
https://github.com/dropbox/rust-alloc-no-stdlib/blob/6032b6a9b20e03737135c55a0270ccffcc1438ef/src/lib.rs#L41

I believe the safety contract should mention that:
- the caller must guarantee that the allocator passed in can be safely called (including the corner-case of having a 0 argument for size), and returns buffers of the appropriate size.
- the correct relationship between `alloc` and `free` is upheld (free must be a valid function to free the memory allocated by `alloc`)
- computing `num_elements * sizeof(T)` must not overflow -- unless that is checked in the body of the function.

Moreover, using the macro with `malloc` is *always* unsound unless `T` is `MaybeUninit<_>`: `new` will end up creating a reference to a slice of uninitialized data, which is UB.
Even using the function with `calloc` might be unsound if `0` is not a valid bit pattern for `T`.
Similarly, when using a custom allocator, the bitpatterns returned by the custom allocator should be valid for `T`.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Comienza en src/lib.rs, alrededor de CallocBackingStore::new y la macro define_allocator_memory_pool. Revisa cómo se utilizan los callbacks del allocator y el slice, y documenta después las invariantes de seguridad identificadas en el issue, incluida la compatibilidad entre asignación y liberación y los patrones de bits válidos. Se considera terminado cuando ambos puntos de entrada unsafe indican claramente las garantías requeridas del llamador.

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

Evaluación

Stack tecnológico
rust
Área
operating-systems
Tipo de issue
Documentación
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.