boostorg / boostorg/filesystem
boost::filesystem crashes on Musl/Alpine Linux when locale environment variables are unset
- Dominant language
- C++
- Stars
- 180
- Forks
- 168
- PR merge metrics
- No merged PRs in 30d
Description
On Musl-libc based systems (e.g., Alpine Linux), boost::filesystem throws a runtime exception (locale::facet::_S_create_c_locale name not valid) during path initialization if LANG or LC_ALL environment variables are missing or misconfigured.
The issue stems from default_locale() in
[https://github.com/boostorg/filesystem/blob/d73863751bf0570fc82f1b49246f909cea61083b/src/path.cpp#L1456-L1470](https://github.com/boostorg/filesystem/blob/d73863751bf0570fc82f1b49246f909cea61083b/src/path.cpp#L1456-L1470)
```c++
std::locale default_locale()
{
#if defined(BOOST_FILESYSTEM_WINDOWS_API)
...
#elif defined(BOOST_FILESYSTEM_DETAIL_USE_UTF8_CODECVT_FACET)
std::locale global_loc = std::locale();
return std::locale(global_loc, new boost::filesystem::detail::utf8_codecvt_facet());
#else // Other POSIX
return std::locale(""); // 💥 Crashes here on Musl if env is invalid !!!
#endif
}
```
On Musl/Alpine, std::locale("") forces the C++ standard library to look up system locale files. Since Musl does not have built-in localization data generation (locale-gen), this call fails immediately with a fatal runtime error.
Suggested Solution
We need a reliable way to completely bypass std::locale("") on environment-constrained or containerized systems.
Defining BOOST_FILESYSTEM_DETAIL_USE_UTF8_CODECVT_FACET should compile out the std::locale("") path entirely and force-fallback to Boost's internal utf8_codecvt_facet, making path initialization fully independent of host environment variables.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in src/path.cpp at default_locale(), especially the POSIX std::locale("") branch, and inspect how BOOST_FILESYSTEM_DETAIL_USE_UTF8_CODECVT_FACET is enabled. Reproduce path initialization on Musl/Alpine with LANG or LC_ALL unset or invalid. Done means initialization no longer throws in that environment while the existing locale behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, linux
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100