`recursion/gnark-ffi` frees C strings allocated by Go from Rust code
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 38/100
Línea de trabajo
Comienza con recursion/gnark-ffi/go/main.go en las líneas 41–44 y con el código Rust FFI que analiza las cadenas de error devueltas; lee primero la documentación enlazada de Rust sobre CString/from_raw y las cadenas de cgo. Confirma el propietario de cada asignación y asegúrate de que tanto la ruta normal como las rutas de cadenas de error utilicen el mecanismo de liberación compatible con el allocator; terminado significa que ninguna Rust CString toma posesión de punteros asignados por Go.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
From https://github.com/wormhole-foundation/wp1/pull/222#discussion_r1613607167:
The usage of CString by recursion/gnark-ffi seems incorrect when compared to what the Rust documentation says about ownership. Specifically:
- As far as I can tell, these strings are allocated by the Go code here
- The
CStringdocumentation explicitly says "Other usage (e.g., trying to take ownership of a string that was allocated by foreign code) is likely to lead to undefined behavior or allocator corruption." - This means the string is allocated by Go, but being freed by Rust. This seems possibly unsafe.
- The documentation also says: "Note: If you need to borrow a string that was allocated by foreign code, use CStr. If you need to take ownership of a string that was allocated by foreign code, you will need to make your own provisions for freeing it appropriately, likely with the foreign code’s API to do that."
- The correct solution would be to return these pointers and have the Go side free them from Go
- The CGo documentation for strings says:
// Go string to C string // The C string is allocated in the C heap using malloc. // It is the caller's responsibility to arrange for it to be // freed, such as by calling C.free (be sure to include stdlib.h // if C.free is needed). func C.CString(string) *C.char CStringin Rust is actually allocated from the Rust global allocator and not C's malloc/free functions. So this code is freeing something allocated by malloc with Rust's allocator, which is just incorrect in terms of safety- Since this code does seem to work, in some cases where Rust and Go are using the same libc on the same system, this is likely to be incidentally fine
- Further, in some cases, such as when binaries are distributed in pre-compiled formats, it is possible for there to be a version mismatch between libcs used, leading to further issues even if the Rust global allocator ends up using malloc/free
- This same mishandling is present when parsing the error strings returned by Go
- Lenguaje dominante
- Rust
- Estrellas
- 80
- Forks
- 8
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de argumentcomputer/sphinx
-
Dificultad 4/5 3-5 días Aptitud para principiantes 38/100
argumentcomputer/sphinx#206 ·
-
The termination check is under-constrained due to incomplete check of "public_values.next_pc == 0".Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
argumentcomputer/sphinx#205 ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
argumentcomputer/sphinx#204 ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
argumentcomputer/sphinx#188 ·
-
SHA-512 improvementsAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
argumentcomputer/sphinx#181 ·
Todos los issues de argumentcomputer/sphinx
Issues similares
-
Docs: refresh target-app-parity and file-format-parity against mainPosiblemente ocupada @vangel76 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
storytold/photocraft#4417 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
bevyengine/dlss_wgpu#37 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
wgpu error: Validation ErrorAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 63/100
bherbruck/solvecraft#369 ·
-
enhancement
Dificultad 1/5 Menos de una hora Aptitud para principiantes 83/100
alunduil/git-worktree-poi#11 ·