Skip to content

[C++] Assertion fires when trying to parse json #47417

Description

@gvol

Describe the bug, including details regarding any error messages, version, and platform.

When I build (in debug) and run the code below I get the following assertion firing:

$ ./arrow_json
/Users/iandrus/.conan2/p/b/arrow4b55108a32d91/b/src/cpp/src/arrow/json/parser.cc:540: Check failed: (builder) == (parent.kind == Kind::kArray ? Cast<Kind::kArray>(parent)->value_builder() : Cast<Kind::kObject>(parent)->field_builder(field_index))
Abort trap: 6 ./arrow_json

Needless to say, it shouldn't abort on this, but rather fail to parse (if it's not valid—though it seems to me that it should be valid).

#include <arrow/buffer.h>
#include <arrow/io/api.h>
#include <arrow/json/api.h>
#include <arrow/status.h>
#include <memory>
#include <string>
int main( void ) {
std::string json_data = R"json({
"all_nulls": [null, null, null]
})json";
auto buffer = std::make_shared<::arrow::Buffer>(
reinterpret_cast<uint8_t const *>( json_data.data() ),
json_data.size() );
auto input = std::make_shared<::arrow::io::BufferReader>( buffer );
auto reader = ::arrow::json::TableReader::Make(
::arrow::default_memory_pool(),
input,
::arrow::json::ReadOptions::Defaults(),
::arrow::json::ParseOptions::Defaults() );
if ( !reader.ok() ) {
return 1;
}
auto result = (*reader)->Read();
return result.ok() ? 0 : 1;
}
// clang++ -o ./arrow_json ./arrow_json_main.cpp -isystem /Users/iandrus/.conan2/p/b/arrow4b55108a32d91/p/include -std=c++20 -L /Users/iandrus/.conan2/p/b/arrow4b55108a32d91/p/lib/ -larrow -larrow_bundled_dependencies -L /Users/iandrus/.conan2/p/b/snapp07bbfca910b63/p/lib/ -lsnappy -L /Users/iandrus/.conan2/p/b/zstde2aeb565ce8ea/p/lib -lzstd -L/Users/iandrus/.conan2/p/b/zlibb749ff5e66dc6/p/lib -lz

Changing the json to have [null, "hi", null] gives a different assertion. After some experimenting, the trouble seems to be the null in the first position.

/Users/iandrus/.conan2/p/b/arrow4b55108a32d91/b/src/cpp/src/arrow/json/parser.cc:1151: Check failed: (list_builder->value_builder()) == (builder_)
Abort trap: 6 ./arrow_json

Component(s)

C++

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions