You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "hakanuzum (via GitHub)" <gi...@apache.org> on 2026/04/23 20:31:16 UTC

[I] [Bug](function) count_substrings returns wrong result for overlapping pattern boundary [doris]

hakanuzum opened a new issue, #62768:
URL: https://github.com/apache/doris/issues/62768

   ### Search before asking
   - [x] I searched in the issues and found no similar issues.
   
   ### Version
   master (after PR #62262)
   
   ### What happened
   `count_substrings('ccc', 'cc')` returns **2** instead of expected **1** (non-overlapping count).
   
   The regression test `test_string_all.groovy` expects 1, but BE returns 2, causing `cloud_p0` CI failures.
   
   ### Root Cause
   In PR #62262, `function_string.h` was split into `function_string_search.cpp`. The `find_pos()` function checks `pos < str_size` but does not verify `pos + pattern_ref.size <= str_size`, so it matches a pattern that extends beyond the string boundary via `memcmp_small_allow_overflow15`.
   
   ```cpp
   // function_string_search.cpp, find_pos()
   while (pos < str_size &&    // ← should be: pos + pattern_ref.size <= str_size
          memcmp_small_allow_overflow15(...)) {
       pos++;
   }
   ```
   
   For `count_substrings('ccc', 'cc')`:
   - pos=0: matches `cc` at [0,1] → count=1, advance to pos=2
   - pos=2: `pos < str_size` (2 < 3) is true, memcmp reads bytes [2,3] which overflows → false match → count=2
   
   ### Expected behavior
   `count_substrings('ccc', 'cc')` should return **1** (non-overlapping).
   
   ### How to reproduce
   ```sql
   SELECT count_substrings('ccc', 'cc');
   -- Returns: 2
   -- Expected: 1
   ```
   
   ### Anything else
   This causes `qt_count_substrings_53` in `test_string_all.groovy` to fail in CI.
   Introduced by refactoring PR #62262.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [I] [Bug](function) count_substrings returns wrong result for overlapping pattern boundary [doris]

Posted by "HappenLee (via GitHub)" <gi...@apache.org>.
HappenLee closed issue #62768: [Bug](function) count_substrings returns wrong result for overlapping pattern boundary
URL: https://github.com/apache/doris/issues/62768


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org