{"record":{"id":"7913f302b0ca9e55","repo":"BoundaryML/baml","slug":"invalid-library-path-w","errorCode":null,"errorMessage":"invalid library path: %w","messagePattern":"invalid library path: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/baml_go/lib_windows.go","lineNumber":33,"sourceCode":"\t\"fmt\"\n\t\"syscall\"\n\t\"unsafe\"\n)\n\nvar (\n\tkernel32 = syscall.NewLazyDLL(\"kernel32.dll\")\n\n\tprocLoadLibraryW   = kernel32.NewProc(\"LoadLibraryW\")\n\tprocGetProcAddress = kernel32.NewProc(\"GetProcAddress\")\n\tprocFreeLibrary    = kernel32.NewProc(\"FreeLibrary\")\n\tprocGetLastError   = kernel32.NewProc(\"GetLastError\")\n)\n\n// loadLibrary loads the shared library using LoadLibrary\nfunc loadLibrary(path string) (unsafe.Pointer, error) {\n\tpathPtr, err := syscall.UTF16PtrFromString(path)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid library path: %w\", err)\n\t}\n\n\thandle, _, err := procLoadLibraryW.Call(uintptr(unsafe.Pointer(pathPtr)))\n\tif handle == 0 {\n\t\tlastErr, _, _ := procGetLastError.Call()\n\t\treturn nil, fmt.Errorf(\"LoadLibrary failed for %s: error code %d: %w\", path, lastErr, err)\n\t}\n\n\treturn unsafe.Pointer(handle), nil\n}\n\n// getSymbol retrieves a symbol from the loaded library\nfunc getSymbol(handle unsafe.Pointer, name string) (unsafe.Pointer, error) {\n\tnamePtr, err := syscall.BytePtrFromString(name)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid symbol name: %w\", err)\n\t}\n","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/baml_go/lib_windows.go#L15-L51","documentation":"loadLibrary on Windows converts the shared-library path to a UTF-16 pointer via syscall.UTF16PtrFromString before calling LoadLibraryW. This error is returned when that conversion fails, which happens only for paths containing NUL (0x00) bytes — the Windows API cannot accept embedded nulls. It wraps the original syscall error.","triggerScenarios":"Calling loadLibrary (indirectly via BAML runtime initialization) with a library path string containing a NUL character, e.g. a path built from a zero-terminated buffer or truncated string.","commonSituations":"Paths read from binary config or environment buffers without trimming at the terminator; path manipulation that appends \"\\x00\"; corrupted configuration values where a null byte snuck into the DLL location.","solutions":["Sanitize the library path: strip everything from the first NUL byte before passing it to the runtime (strings.SplitN(path, \"\\x00\", 2)[0]).","Check where the path originates (config file, env var) and fix the producer that is emitting embedded nulls.","Validate the path with strings.ContainsRune(path, 0) before initializing the BAML runtime.","Re-encode the path from its source (e.g. re-read env var with os.Getenv) to remove corruption."],"exampleFix":"// before\nruntime.Init(path) // path contains \"C:\\\\libs\\\\baml.dll\\x00junk\"\n\n// after\ncleanPath := strings.SplitN(path, \"\\x00\", 2)[0]\nif strings.ContainsRune(cleanPath, 0) {\n    return fmt.Errorf(\"path still contains NUL\")\n}\nruntime.Init(cleanPath)","handlingStrategy":"validation","validationCode":"if strings.ContainsRune(path, 0) {\n    return fmt.Errorf(\"library path contains NUL byte: %q\", path)\n}","typeGuard":"func validLibPath(p string) bool {\n    return p != \"\" && !strings.ContainsRune(p, 0)\n}","tryCatchPattern":"if _, err := syscall.UTF16PtrFromString(path); err != nil {\n    return fmt.Errorf(\"bad library path: %w\", err)\n}","preventionTips":["Trim NUL terminators when paths come from binary buffers or C interop.","Validate library paths with os.Stat before runtime initialization.","Keep paths as plain Go strings from trusted sources (os.Getenv, flags)."],"tags":["windows","dynamic-linking","path-validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}