google / jsonnet

Jsonnet - The data templating language
http://jsonnet.org
Apache License 2.0
6.87k stars 436 forks source link

Crash (assert/check fail) in RapidYAML if the input is a YAML stream #1148

Open johnbartholomew opened 4 months ago

johnbartholomew commented 4 months ago

While trying to reproduce #1147 I hit this assert/check-fail (building with Makefile at cb18fec3721375ddfc938cb4831835ec06c64d81)

❯ ./jsonnet -e 'std.parseYaml("1\n---")'
third_party/rapidyaml/ryml_all.hpp:22998:check failed: !m_tree->is_stream(id)
Aborted (core dumped)
(gdb) bt
#0  0x00005555555e7000 in trap_instruction () at third_party/rapidyaml/ryml_all.hpp:1724
#1  debug_break () at third_party/rapidyaml/ryml_all.hpp:1819
#2  c4::yml::Emitter<c4::yml::WriterOStream<std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> > > >::_do_visit_json (this=this@entry=0x7fffffffbe90, id=id@entry=0)
    at third_party/rapidyaml/ryml_all.hpp:22998
#3  0x00005555555d89e9 in c4::yml::Emitter<c4::yml::WriterOStream<std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> > > >::emit_as (error_on_excess=true, id=0, t=..., 
    type=c4::yml::EMIT_JSON, this=0x7fffffffbe90) at third_party/rapidyaml/ryml_all.hpp:22564
#4  c4::yml::operator<< <std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> > > (j=..., s="") at third_party/rapidyaml/ryml_all.hpp:22253
#5  jsonnet::internal::(anonymous namespace)::Interpreter::yamlTreeToJson (this=this@entry=0x7fffffffd720, tree=...) at core/vm.cpp:1657
#6  0x00005555555d98ce in jsonnet::internal::(anonymous namespace)::Interpreter::builtinParseYaml (this=0x7fffffffd720, loc=..., args=...) at core/vm.cpp:1622
#7  0x00005555555cd8ed in jsonnet::internal::(anonymous namespace)::Interpreter::evaluate (this=this@entry=0x7fffffffd720, ast_=0x55555569a5a0, ast_@entry=0x5555559e67e0, 
    initial_stack_size=initial_stack_size@entry=0) at core/vm.cpp:2680
#8  0x00005555555d38dd in jsonnet::internal::jsonnet_vm_execute (alloc=alloc@entry=0x7fffffffdbe0, ast=0x5555559e67e0, ext_vars=std::map with 0 elements, max_stack=max_stack@entry=502, 
    gc_min_objects=<optimized out>, gc_growth_trigger=<optimized out>, natives=std::map with 0 elements, 
    import_callback=0x55555559b53c <default_import_callback(void*, char const*, char const*, char**, char**, size_t*)>, ctx=0x5555556997b0, string_output=false) at core/vm.cpp:3348
#9  0x0000555555593f6c in jsonnet_evaluate_snippet_aux (vm=0x5555556997b0, filename=<optimized out>, snippet=0x5555556998e0 "std.parseYaml(\"1\\n---\")", error=0x7fffffffde78, 
    kind=kind@entry=(anonymous namespace)::REGULAR) at core/libjsonnet.cpp:564
#10 0x00005555555947b1 in jsonnet_evaluate_snippet (vm=<optimized out>, filename=<optimized out>, snippet=<optimized out>, error=<optimized out>) at core/libjsonnet.cpp:716
#11 0x000055555556191e in main (argc=<optimized out>, argv=<optimized out>) at /usr/include/c++/13.2.1/bits/basic_string.h:222