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 cudf::strings::replace_with_backrefs hang on empty match result #13418

Merged
merged 6 commits into from
May 25, 2023

Conversation

davidwendt
Copy link
Contributor

Description

Fixes bug where the cudf::strings::replace_with_backrefs goes into an infinite loop when an match results in an empty string. After each replace occurs, the logic continues to search for matches on the remainder of the string. Each new starting point must account for the previous match being empty.
Also included a gtest for this case.

Closes #13404

Checklist

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

@davidwendt davidwendt added bug Something isn't working 3 - Ready for Review Ready for review by team libcudf Affects libcudf (C++/CUDA) code. strings strings issues (C++ and Python) non-breaking Non-breaking change labels May 23, 2023
@davidwendt davidwendt self-assigned this May 23, 2023
@davidwendt davidwendt requested a review from a team as a code owner May 23, 2023 18:39
@davidwendt
Copy link
Contributor Author

@andygrove verified this fixes the bug he reported in #13404

@GregoryKimball GregoryKimball requested a review from bdice May 24, 2023 20:14
Copy link
Contributor

@GregoryKimball GregoryKimball 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 David for addressing this failure!

Copy link
Member

@PointKernel PointKernel left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks!

cpp/src/strings/replace/backref_re.cuh Show resolved Hide resolved
@@ -61,14 +61,15 @@ struct backrefs_fn {
auto out_ptr = d_chars ? (d_chars + d_offsets[idx]) : nullptr;
size_type lpos = 0; // last byte position processed in d_str
size_type begin = 0; // first character position matching regex
size_type end = nchars; // last character position (exclusive)
size_type end = -1; // last character position (exclusive)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
size_type end = -1; // last character position (exclusive)
size_type end = -1; // last character position

no longer relevant

@davidwendt
Copy link
Contributor Author

/merge

@rapids-bot rapids-bot bot merged commit 960cc42 into rapidsai:branch-23.06 May 25, 2023
@davidwendt davidwendt deleted the bug-backref-hang branch May 25, 2023 11:53
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 libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change strings strings issues (C++ and Python)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] replace_with_backrefs hangs with some inputs
4 participants