Skip to content

GH-55497: [C++] Avoid reusing simdjson values after failed get() - #55498

Open
wgtmac wants to merge 3 commits into
apache:mainfrom
wgtmac:fix_simdjson_ub
Open

wgtmac wants to merge 3 commits into
apache:mainfrom
wgtmac:fix_simdjson_ub

Conversation

@wgtmac

@wgtmac wgtmac commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Rationale for this change

Fix UB in StructConverter::AppendValue(), which reused a simdjson ondemand value after get(array) failed.

See #55497.

What changes are included in this PR?

  • Determine the JSON type before calling get() in BooleanConverter, TimestampConverter, and StructConverter.
  • Refactor GetJsonAs() and IsJsonNull() to avoid accessing a value after a failed typed access.

Are these changes tested?

Added a case matching the nested struct/object notation from the issue.

Are there any user-facing changes?

No.

Was AI used for this PR?

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

Copilot AI balanced review requested due to automatic review settings November 11, 2026 09:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@wgtmac

wgtmac commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

Our internal integration crashed due to this UB. I've proposed a fix, please take a look when you have time. Thanks! @kou @pitrou @Reranko05

Comment thread cpp/src/arrow/util/simdjson_internal.cc Resolved
Copilot AI balanced review requested due to automatic review settings November 12, 2026 08:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@wgtmac

wgtmac commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

@rok I saw you have some relevant commits. Could you help review this?

Comment thread cpp/src/arrow/json/from_string.cc Outdated
Comment on lines +170 to +179
ARROW_ASSIGN_OR_RAISE(
auto json_type, internal::ResolveSimdjsonResult(json_obj.type(),
"Failed to determine JSON type"));
if (json_type == sj::json_type::number) {
ARROW_ASSIGN_OR_RAISE(auto int_value, internal::GetJsonAs<int64_t>(json_obj));
return builder_->Append(int_value != 0);
}
if (json_type != sj::json_type::boolean) {
return Status::Invalid("Expected JSON boolean for type ", type_->ToString());
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic seems to repeat at least partially two more times below. Could we abstract it into the helper as well? Not at any cost of course.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Added a GetJsonType helper to save some typing.

@rok

rok commented Nov 13, 2026

Copy link
Copy Markdown
Member

@wgtmac looks good, I'd DRY it a bit if possible, not other thoughts.
@Reranko05 worked on this, perhaps he has input.

@Reranko05

Copy link
Copy Markdown
Collaborator

I am a bit preoccupied with my university exams right now. I will take a look at this tomorrow!

@rok

rok commented Nov 13, 2026

Copy link
Copy Markdown
Member

@Reranko05 goog luck with the exams, please ignore this until they are past.

@Reranko05 Reranko05 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I agree with @rok suggestion about introducing an abstraction, but I don't consider it blocking.

Copilot AI balanced review requested due to automatic review settings November 15, 2026 15:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants