[Crash] Lix crashes on nix-instantiate --parse of strings with invalid UTF-8 #1052

Open
opened 2025-11-27 17:25:42 +00:00 by commentatorforall · 0 comments

Describe the bug

This crash was discoved by flaker

Lix crashed, while calling nix-instantiate --parse ./tests/functional/lang/eval-fail-toJSON-non-utf-8.nix of the CppNix repository /tests/functional/lang/eval-fail-toJSON-non-utf-8.nix

Effectively, when calling builtins.toJson with a string not conforming to utf-8, it crashes

Exception: nlohmann::json_abi_v3_11_3::detail::type_error: [json.exception.type_error.316] invalid UTF-8 byte at index 16: 0xFF
Stack trace:
0# nix::getStackTraceabi:cxx11 in /nix/store/p89s0as08llbz0v12ph7cyc7v373x97p-lix-2.95.0pre19700101-dev_dirty/lib/liblixutil.so
1# nix::logException(std::basic_string_view<char, std::char_traits >, std::exception const&) in /nix/store/p89s0as08llbz0v12ph7cyc7v373x97p-lix-2.95.0pre19700101-dev_dirty/lib/liblixutil.so
2# 0x00007FFFF7F8EAB4 in /nix/store/p89s0as08llbz0v12ph7cyc7v373x97p-lix-2.95.0pre19700101-dev_dirty/lib/liblixmain.so
3# 0x00007FFFF60BF1AA in /nix/store/dj06r96j515npcqi9d8af1d1c60bx2vn-gcc-14.3.0-lib/lib/libstdc++.so.6
4# std::unexpected() in /nix/store/dj06r96j515npcqi9d8af1d1c60bx2vn-gcc-14.3.0-lib/lib/libstdc++.so.6
5# 0x00007FFFF60BF427 in /nix/store/dj06r96j515npcqi9d8af1d1c60bx2vn-gcc-14.3.0-lib/lib/libstdc++.so.6
6# nlohmann::json_abi_v3_11_3::detail::serializer<nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator >, void> >::dump_escaped(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, bool) in nix-instantiate
7# nlohmann::json_abi_v3_11_3::detail::serializer<nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator >, void> >::dump(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator >, void> const&, bool, bool, unsigned int, unsigned int) in nix-instantiate
8# nlohmann::json_abi_v3_11_3::detail::serializer<nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator >, void> >::dump(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator >, void> const&, bool, bool, unsigned int, unsigned int) in nix-instantiate
9# nlohmann::json_abi_v3_11_3::detail::serializer<nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator >, void> >::dump(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator >, void> const&, bool, bool, unsigned int, unsigned int) in nix-instantiate
10# nlohmann::json_abi_v3_11_3::detail::serializer<nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator >, void> >::dump(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator >, void> const&, bool, bool, unsigned int, unsigned int) in nix-instantiate
11# nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator >, void>::dump(int, char, bool, nlohmann::json_abi_v3_11_3::detail::error_handler_t) const in nix-instantiate
12# 0x000055555580F2A9 in nix-instantiate
13# 0x000055555581122D in nix-instantiate
14# 0x0000555555673DDB in nix-instantiate
15# 0x000055555571C57C in nix-instantiate
16# 0x000055555572093B in nix-instantiate
17# nix::handleExceptions(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::function<int ()>) in /nix/store/p89s0as08llbz0v12ph7cyc7v373x97p-lix-2.95.0pre19700101-dev_dirty/lib/liblixmain.so
18# 0x00005555557201EB in nix-instantiate
19# 0x00007FFFF5C2A47E in /nix/store/g8zyryr9cr6540xsyg4avqkwgxpnwj2a-glibc-2.40-66/lib/libc.so.6
20# __libc_start_main in /nix/store/g8zyryr9cr6540xsyg4avqkwgxpnwj2a-glibc-2.40-66/lib/libc.so.6
21# 0x00005555556377F5 in nix-instantiate

If you have a problem with a specific package or NixOS,
you probably want to file an issue at https://github.com/NixOS/nixpkgs/issues.

Steps To Reproduce

  1. run nix-instantiate --parse ./tests/functional/lang/eval-fail-toJSON-non-utf-8.nix (of the cppnix repo, not ours

Expected behavior

A clear error message instead of a crash

nix --version output

(dev build of feature deprecations, but no change on main)
/nix/store/p89s0as08llbz0v12ph7cyc7v373x97p-lix-2.95.0pre19700101

## Describe the bug > This crash was discoved by flaker Lix crashed, while calling `nix-instantiate --parse ./tests/functional/lang/eval-fail-toJSON-non-utf-8.nix` of the CppNix repository [/tests/functional/lang/eval-fail-toJSON-non-utf-8.nix](https://github.com/NixOS/nix/blob/master/tests/functional/lang/eval-fail-toJSON-non-utf-8.nix) Effectively, when calling `builtins.toJson` with a string not conforming to utf-8, it crashes Exception: nlohmann::json_abi_v3_11_3::detail::type_error: [json.exception.type_error.316] invalid UTF-8 byte at index 16: 0xFF Stack trace: 0# nix::getStackTrace[abi:cxx11]() in /nix/store/p89s0as08llbz0v12ph7cyc7v373x97p-lix-2.95.0pre19700101-dev_dirty/lib/liblixutil.so 1# nix::logException(std::basic_string_view<char, std::char_traits<char> >, std::exception const&) in /nix/store/p89s0as08llbz0v12ph7cyc7v373x97p-lix-2.95.0pre19700101-dev_dirty/lib/liblixutil.so 2# 0x00007FFFF7F8EAB4 in /nix/store/p89s0as08llbz0v12ph7cyc7v373x97p-lix-2.95.0pre19700101-dev_dirty/lib/liblixmain.so 3# 0x00007FFFF60BF1AA in /nix/store/dj06r96j515npcqi9d8af1d1c60bx2vn-gcc-14.3.0-lib/lib/libstdc++.so.6 4# std::unexpected() in /nix/store/dj06r96j515npcqi9d8af1d1c60bx2vn-gcc-14.3.0-lib/lib/libstdc++.so.6 5# 0x00007FFFF60BF427 in /nix/store/dj06r96j515npcqi9d8af1d1c60bx2vn-gcc-14.3.0-lib/lib/libstdc++.so.6 6# nlohmann::json_abi_v3_11_3::detail::serializer<nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> >::dump_escaped(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) in nix-instantiate 7# nlohmann::json_abi_v3_11_3::detail::serializer<nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> >::dump(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> const&, bool, bool, unsigned int, unsigned int) in nix-instantiate 8# nlohmann::json_abi_v3_11_3::detail::serializer<nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> >::dump(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> const&, bool, bool, unsigned int, unsigned int) in nix-instantiate 9# nlohmann::json_abi_v3_11_3::detail::serializer<nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> >::dump(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> const&, bool, bool, unsigned int, unsigned int) in nix-instantiate 10# nlohmann::json_abi_v3_11_3::detail::serializer<nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> >::dump(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> const&, bool, bool, unsigned int, unsigned int) in nix-instantiate 11# nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nix::json::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void>::dump(int, char, bool, nlohmann::json_abi_v3_11_3::detail::error_handler_t) const in nix-instantiate 12# 0x000055555580F2A9 in nix-instantiate 13# 0x000055555581122D in nix-instantiate 14# 0x0000555555673DDB in nix-instantiate 15# 0x000055555571C57C in nix-instantiate 16# 0x000055555572093B in nix-instantiate 17# nix::handleExceptions(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<int ()>) in /nix/store/p89s0as08llbz0v12ph7cyc7v373x97p-lix-2.95.0pre19700101-dev_dirty/lib/liblixmain.so 18# 0x00005555557201EB in nix-instantiate 19# 0x00007FFFF5C2A47E in /nix/store/g8zyryr9cr6540xsyg4avqkwgxpnwj2a-glibc-2.40-66/lib/libc.so.6 20# __libc_start_main in /nix/store/g8zyryr9cr6540xsyg4avqkwgxpnwj2a-glibc-2.40-66/lib/libc.so.6 21# 0x00005555556377F5 in nix-instantiate If you have a problem with a specific package or NixOS, you probably want to file an issue at https://github.com/NixOS/nixpkgs/issues. ## Steps To Reproduce 1. run `nix-instantiate --parse ./tests/functional/lang/eval-fail-toJSON-non-utf-8.nix` (of the cppnix repo, not ours ## Expected behavior A clear error message instead of a crash ## `nix --version` output (dev build of feature deprecations, but no change on main) /nix/store/p89s0as08llbz0v12ph7cyc7v373x97p-lix-2.95.0pre19700101
commentatorforall changed title from [Crash] Lix crashes on parsing JSON files with invalid UTF-8 to [Crash] Lix crashes on nix-instantiate --parse of strings with invalid UTF-8 2025-11-27 17:28:27 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lix-project/lix#1052
No description provided.