Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JSON parsing memory corruption - Fix Mixed types nested children removal #15798

Merged

Conversation

karthikeyann
Copy link
Contributor

Description

Fixes #15750
The references of deleted child columns are not removed, which caused segfault, and also memory errors (found with valgrind). This fix removes references of child columns and deletes them recursively.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@karthikeyann karthikeyann added bug Something isn't working 2 - In Progress Currently a work in progress cuIO cuIO issue non-breaking Non-breaking change labels May 21, 2024
@karthikeyann karthikeyann requested a review from shrshi May 21, 2024 04:49
@github-actions github-actions bot added the libcudf Affects libcudf (C++/CUDA) code. label May 21, 2024
@karthikeyann karthikeyann added 3 - Ready for Review Ready for review by team and removed 2 - In Progress Currently a work in progress labels May 30, 2024
@karthikeyann karthikeyann marked this pull request as ready for review May 30, 2024 07:42
@karthikeyann karthikeyann requested a review from a team as a code owner May 30, 2024 07:42
@karthikeyann karthikeyann requested a review from davidwendt May 30, 2024 07:42
@@ -594,8 +594,7 @@ void make_device_json_column(device_span<SymbolT const> input,
col.validity =
cudf::detail::create_null_mask(col.num_rows, cudf::mask_state::ALL_NULL, stream, mr);
col.type = json_col_t::StringColumn;
col.child_columns.clear(); // their references should be deleted too.
col.column_order.clear();
// destroy references of all child columns after
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I'm not understanding this comment.
Destroy references of all child columns after what?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is my only comment about this PR as well. Happy to approve once this is fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

'after this step'.

Copy link
Contributor

@shrshi shrshi left a comment

Choose a reason for hiding this comment

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

Thank you for the fix! I have two questions in the test -

cudf::io::json_reader_options::builder(cudf::io::source_info{json_str.c_str(), json_str.size()})
.lines(true)
.recovery_mode(cudf::io::json_recovery_mode_t::RECOVER_WITH_NULL)
.normalize_single_quotes(true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Since we do not have single quotes in the input string, do we need to enable single quotes normalization here? Another minor nit is that we can remove normalize_whitespace call since whitespace normalization is disabled by default.

Copy link
Contributor Author

@karthikeyann karthikeyann May 31, 2024

Choose a reason for hiding this comment

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

Right, those options are not required. I used the same options as repro code for the bug, but I reduced the input json to minimal.

ASSERT_EQ(result.metadata.schema_info[0].children[0].children.size(), 2);
EXPECT_EQ(result.metadata.schema_info[0].children[0].children[0].name, "offsets");
// types
EXPECT_EQ(result.tbl->get_column(0).type().id(), cudf::type_id::STRUCT);
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Can type checks also be ASSERT_EQ? I think the types condition must hold since the goal of the test is to ensure correct mixed types behaviour,

Copy link
Contributor

Choose a reason for hiding this comment

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

The EXPECT_EQ will fail the test as appropriate.
The difference is that ASSERT_EQ will abort the test which should really only be used when the remaining code may fail/segfault.
I think the usage of EXPECT_EQ and ASSERT_EQ are correctly implemented here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, thank you for the explanation!

Copy link
Contributor

@bdice bdice left a comment

Choose a reason for hiding this comment

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

My questions have been answered. Thanks!

@karthikeyann
Copy link
Contributor Author

/merge

@rapids-bot rapids-bot bot merged commit 476db9f into rapidsai:branch-24.08 May 31, 2024
70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for Review Ready for review by team bug Something isn't working cuIO cuIO issue libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] double free or memory corruption when parsing some JSON
4 participants