Skip to content

Commit

Permalink
ARROW-12774 : [C++][Compute] replace_substring_regex() creates invali…
Browse files Browse the repository at this point in the history
…d arrays => crash

fixing ARROW-12774

Closes #10320 from nirandaperera/ARROW-12774

Authored-by: niranda perera <[email protected]>
Signed-off-by: Yibo Cai <[email protected]>
  • Loading branch information
nirandaperera authored and cyb70289 committed May 15, 2021
1 parent f47703e commit 068318f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cpp/src/arrow/compute/kernels/scalar_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ struct ReplaceSubString {

if (batch[0].kind() == Datum::ARRAY) {
// We already know how many strings we have, so we can use Reserve/UnsafeAppend
RETURN_NOT_OK(offset_builder.Reserve(batch[0].array()->length));
RETURN_NOT_OK(offset_builder.Reserve(batch[0].array()->length + 1));
offset_builder.UnsafeAppend(0); // offsets start at 0

const ArrayData& input = *batch[0].array();
Expand Down
8 changes: 8 additions & 0 deletions cpp/src/arrow/compute/kernels/scalar_string_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,14 @@ TYPED_TEST(TestStringKernels, ReplaceSubstringRegex) {
ReplaceSubstringOptions options_regex2{"(a.a)", "aba\\1"};
this->CheckUnary("replace_substring_regex", R"(["aaaaaa"])", this->type(),
R"(["abaaaaabaaaa"])", &options_regex2);

// ARROW-12774
ReplaceSubstringOptions options_regex3{"X", "Y"};
this->CheckUnary("replace_substring_regex",
R"(["A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A"])",
this->type(),
R"(["A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A"])",
&options_regex3);
}

TYPED_TEST(TestStringKernels, ReplaceSubstringRegexLimited) {
Expand Down

0 comments on commit 068318f

Please sign in to comment.