[BUG] Windows: getErrorMessage() reads uninitialized pointer when FormatMessage fails
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 74/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Tranquilo
- Stack tecnológico
- cpp
- Área
- operating-systems
Línea de trabajo
Comienza con src/backend/common/module_loading_windows.cpp:31-41 e inspecciona la llamada a FormatMessage y sus invocadores en src/api/unified/symbol_manager.cpp y en los demás archivos de módulo indicados. Verifica la ruta de fallo antes de construir el string y la liberación de la asignación en la ruta exitosa; se considera terminado cuando un formateo fallido ya no desreferencia un puntero no inicializado y las llamadas exitosas no dejan fugas del búfer de LocalAlloc.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
On Windows, getErrorMessage() constructs a std::string from lpMsgBuf without checking whether FormatMessage actually wrote to it. When FormatMessage fails, lpMsgBuf is still uninitialized and std::string's constructor runs strlen on an indeterminate stack value.
It also leaks the LocalAlloc'd buffer on the success path.
Description
src/backend/common/module_loading_windows.cpp:31-41:
string getErrorMessage() {
const char* lpMsgBuf; // uninitialized
DWORD dw = GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf, 0, NULL);
string error_message(lpMsgBuf); // no check, no LocalFree
return error_message;
}
FormatMessage returns 0 and does not touch the output pointer when the message cannot be formatted — which happens for error codes with no entry in the system message table (common for loader and NTSTATUS-derived codes, and for codes left behind by a DLL whose DllMain failed). The return value is discarded here, so lpMsgBuf is then dereferenced regardless.
FORMAT_MESSAGE_ALLOCATE_BUFFER also requires the caller to LocalFree the buffer; that never happens, so every successful call leaks.
Why this is on a hot path
getErrorMessage() is called on every failed LoadLibrary during backend probing, src/api/unified/symbol_manager.cpp:
AF_TRACE("Failed to load {}", getErrorMessage());
AF_TRACE evaluates its arguments unconditionally — the spdlog level filter applies after the call — so this runs even with tracing disabled. The unified loader tries roughly a dozen path prefixes across each backend, so on a typical process start most of those attempts fail and this function runs tens of times before any user code executes.
Other callers include src/backend/cuda/cusparseModule.cpp, src/backend/cuda/cudnnModule.cpp, and src/backend/common/graphics_common.cpp.
Impact
Reading an indeterminate pointer produces either a garbage error string or STATUS_ACCESS_VIOLATION (0xC0000005), during library initialization and before any user code runs. Intermittent, since it depends on the stack residue at that address.
Reproducible Code and/or Steps
System Information
Checklist
- Using the latest available ArrayFire release
- GPU drivers are up to date
Disclaimer
Found by Claude Opus 5. The prompt was to look for potential sources for 0xC0000005 errors on Windows.
- Lenguaje dominante
- C++
- Estrellas
- 4.9k
- Forks
- 555
- Merge medio
- 1 h 24 min
- PR fusionados (30 d)
- 1
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 arrayfire/arrayfire
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
-
bug
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
-
[BUG] Sparse host call throws Abiertobug
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
Todos los issues de arrayfire/arrayfire
Issues similares
-
ai_reviewed
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
ydb-platform/ydb#53869 · 3 comentarios ·
-
bug cert blocker needs triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
project-chip/connectedhomeip#74373 ·
-
[request] tracy/0.14.1 Abiertoupstream update
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
conan-io/conan-center-index#31035 ·
-
Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
documentation
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
vllm-project/vllm-ascend#17329 ·