Skip to content

Crash on invalid UTF-8 bytes in Natspec #16519

@msooseth

Description

@msooseth

Description

./solc/solc --optimize --ir minimized-from-ab4ee1498fff0c71961d81fc308f1dee0be16f33
Uncaught exception:
Dynamic exception type: nlohmann::json_abi_v3_12_0::detail::type_error
std::exception::what: [json.exception.type_error.316] invalid UTF-8 byte at index 0: 0xF7

Input:

$ xxd minimized-from-ab4ee1498fff0c71961d81fc308f1dee0be16f33
00000000: 2f2f 2ff7 0a63 6f6e 7472 6163 7420 677b  ///..contract g{
00000010: 7d                                       }

GDB backtrace:

(gdb) r
Starting program: /home/matesoos/development/solidity/develop/build/solc/solc --optimize --ir minimized-from-ab4ee1498fff0c71961d81fc308f1dee0be16f33
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Catchpoint 1 (exception thrown), 0x00007ffff7cb213a in __cxxabiv1::__cxa_throw (obj=0x55555649b860, tinfo=0x55555643f578 <typeinfo for nlohmann::json_abi_v3_12_0::detail::type_error>,
    dest=0x555555791a30 <nlohmann::json_abi_v3_12_0::detail::type_error::~type_error()>) at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_throw.cc:81
81        PROBE2 (throw, obj, tinfo);
(gdb) bt
#0  0x00007ffff7cb213a in __cxxabiv1::__cxa_throw (obj=0x55555649b860, tinfo=0x55555643f578 <typeinfo for nlohmann::json_abi_v3_12_0::detail::type_error>,
    dest=0x555555791a30 <nlohmann::json_abi_v3_12_0::detail::type_error::~type_error()>) at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_throw.cc:81
#1  0x000055555613ca04 in nlohmann::json_abi_v3_12_0::detail::serializer<nlohmann::json_abi_v3_12_0::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, nlohmann::json_abi_v3_12_0::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> >::dump_escaped (this=this@entry=0x7fffffffb270, s=<incomplete sequence \367>, ensure_ascii=<optimized out>)
    at /home/matesoos/development/solidity/develop/deps/nlohmann-json/include/nlohmann/detail/output/serializer.hpp:513
#2  0x000055555613fd6c in nlohmann::json_abi_v3_12_0::detail::serializer<nlohmann::json_abi_v3_12_0::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, nlohmann::json_abi_v3_12_0::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> >::dump (this=this@entry=0x7fffffffb270, val=..., pretty_print=pretty_print@entry=false, ensure_ascii=ensure_ascii@entry=true, indent_step=indent_step@entry=0,
    current_indent=current_indent@entry=0) at /home/matesoos/development/solidity/develop/deps/nlohmann-json/include/nlohmann/detail/output/serializer.hpp:250
#3  0x0000555556140230 in nlohmann::json_abi_v3_12_0::detail::serializer<nlohmann::json_abi_v3_12_0::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, nlohmann::json_abi_v3_12_0::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> >::dump (this=this@entry=0x7fffffffb270, val=..., pretty_print=pretty_print@entry=false, ensure_ascii=ensure_ascii@entry=true, indent_step=<optimized out>,
    current_indent=current_indent@entry=0) at /home/matesoos/development/solidity/develop/deps/nlohmann-json/include/nlohmann/detail/output/serializer.hpp:170
#4  0x000055555614033d in nlohmann::json_abi_v3_12_0::detail::serializer<nlohmann::json_abi_v3_12_0::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, nlohmann::json_abi_v3_12_0::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> >::dump (this=this@entry=0x7fffffffb270, val=..., pretty_print=pretty_print@entry=false, ensure_ascii=ensure_ascii@entry=true, indent_step=indent_step@entry=0,
    current_indent=current_indent@entry=0) at /home/matesoos/development/solidity/develop/deps/nlohmann-json/include/nlohmann/detail/output/serializer.hpp:180
#5  0x0000555556140230 in nlohmann::json_abi_v3_12_0::detail::serializer<nlohmann::json_abi_v3_12_0::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, nlohmann::json_abi_v3_12_0::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> >::dump (this=0x7fffffffb270, val=..., pretty_print=pretty_print@entry=false, ensure_ascii=<optimized out>, indent_step=indent_step@entry=0, current_indent=0)
    at /home/matesoos/development/solidity/develop/deps/nlohmann-json/include/nlohmann/detail/output/serializer.hpp:170
#6  0x0000555556140b41 in nlohmann::json_abi_v3_12_0::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, nlohmann::json_abi_v3_12_0::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void>::dump (this=this@entry=0x7fffffffb620,
    indent=indent@entry=-1, indent_char=indent_char@entry=32 ' ', ensure_ascii=ensure_ascii@entry=true,
    error_handler=error_handler@entry=nlohmann::json_abi_v3_12_0::detail::error_handler_t::strict)
    at /home/matesoos/development/solidity/develop/deps/nlohmann-json/include/nlohmann/json.hpp:1313
#7  0x0000555556138441 in solidity::util::jsonPrint (_input=..., _format=...) at /home/matesoos/development/solidity/develop/libsolutil/JSON.cpp:132
#8  solidity::util::jsonCompactPrint (_input=...) at /home/matesoos/development/solidity/develop/libsolutil/JSON.cpp:127
#9  0x0000555555873a72 in solidity::frontend::CompilerStack::createMetadata[abi:cxx11](solidity::frontend::CompilerStack::Contract const&, bool) const (this=this@entry=0x55555649a6c0,
    _contract=..., _forIR=_forIR@entry=true) at /home/matesoos/development/solidity/develop/libsolidity/interface/CompilerStack.cpp:1863
#10 0x0000555555874bcc in solidity::frontend::CompilerStack::createCBORMetadata (this=this@entry=0x55555649a6c0, _contract=..., _forIR=_forIR@entry=true)
    at /home/matesoos/development/solidity/develop/libsolidity/interface/CompilerStack.cpp:1962
#11 0x00005555558774d3 in solidity::frontend::CompilerStack::generateIR (this=this@entry=0x55555649a6c0, _contract=..., _unoptimizedOnly=<optimized out>)
    at /home/matesoos/development/solidity/develop/libsolidity/interface/CompilerStack.cpp:1651
#12 0x000055555587d1e1 in solidity::frontend::CompilerStack::compile (this=0x55555649a6c0, _stopAfter=<optimized out>)
    at /home/matesoos/development/solidity/develop/libsolidity/interface/CompilerStack.cpp:806
#13 0x0000555555762a31 in solidity::frontend::CommandLineInterface::compile (this=this@entry=0x7fffffffc7b0) at /usr/include/c++/15.2.1/bits/unique_ptr.h:192
#14 0x000055555576f320 in solidity::frontend::CommandLineInterface::processInput (this=0x7fffffffc7b0) at /home/matesoos/development/solidity/develop/solc/CommandLineInterface.cpp:859
#15 0x000055555576f720 in solidity::frontend::CommandLineInterface::run (this=this@entry=0x7fffffffc7b0, _argc=_argc@entry=4, _argv=_argv@entry=0x7fffffffccd8)
    at /home/matesoos/development/solidity/develop/solc/CommandLineInterface.cpp:766
#16 0x0000555555725341 in main (argc=4, argv=0x7fffffffccd8) at /home/matesoos/development/solidity/develop/solc/main.cpp:40

Environment

  • Compiler version: latest develop, i.e. 6313134
  • Compilation pipeline (legacy, IR, EOF): default --optimize --ir
  • Target EVM version (as per compiler settings): default latest
  • Framework/IDE (e.g. Foundry, Hardhat, Remix): N/A
  • EVM execution environment / backend / blockchain client: N/A
  • Operating system: Linux

Steps to Reproduce

Run as above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛low effortThere is not much implementation work to be done. The task is very easy or tiny.low impactChanges are not very noticeable or potential benefits are limited.must have eventuallySomething we consider essential but not enough to prevent us from releasing Solidity 1.0 without it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions