fix segmentation fault in process.cdist

This commit is contained in:
Max Bachmann 2022-10-04 01:31:18 +02:00
parent 0ffae8fe09
commit 017bc6ed35
6 changed files with 20 additions and 3 deletions

View File

@ -1,5 +1,10 @@
## Changelog
### [2.11.1] - 2022-10-05
#### Fixed
- Fix segmentation fault in `process.cdist` when used with an empty query sequence
### [2.11.0] - 2022-10-02
#### Changes
- move jarowinkler dependency into rapidfuzz to simplify maintenance

View File

@ -22,7 +22,7 @@ copyright = "2021, Max Bachmann"
author = "Max Bachmann"
# The full version, including alpha/beta/rc tags
release = "2.11.0"
release = "2.11.1"
# -- General configuration ---------------------------------------------------

View File

@ -13,7 +13,7 @@ with open("README.md", encoding="utf8") as f:
setup_args = {
"name": "rapidfuzz",
"version": "2.11.0",
"version": "2.11.1",
"extras_require": {"full": ["numpy"]},
"url": "https://github.com/maxbachmann/RapidFuzz",
"author": "Max Bachmann",

View File

@ -3,6 +3,6 @@ rapid string matching library
"""
__author__: str = "Max Bachmann"
__license__: str = "MIT"
__version__: str = "2.11.0"
__version__: str = "2.11.1"
from rapidfuzz import distance, fuzz, process, string_metric, utils

View File

@ -483,6 +483,9 @@ static Matrix cdist_two_lists_impl(const RF_ScorerFlags* scorer_flags, const RF_
Matrix matrix(dtype, static_cast<size_t>(rows), static_cast<size_t>(cols));
bool multiStringInit = scorer_flags->flags & RF_SCORER_FLAG_MULTI_STRING_INIT;
if (queries.empty() || choices.empty())
return matrix;
if (multiStringInit) {
std::vector<size_t> row_idx(rows);
std::iota(row_idx.begin(), row_idx.end(), 0);

View File

@ -338,5 +338,14 @@ def test_extractOne_use_first_match(scorer):
)
@pytest.mark.parametrize("scorer", [fuzz.ratio, fuzz.WRatio, custom_scorer])
def test_cdist_empty_seq(scorer):
pytest.importorskip("numpy")
assert process_cpp.cdist([], ["a", "b"], scorer=scorer).shape == (0, 2)
assert process_cpp.cdist(["a", "b"], [], scorer=scorer).shape == (2, 0)
assert process_py.cdist([], ["a", "b"], scorer=scorer).shape == (0, 2)
assert process_py.cdist(["a", "b"], [], scorer=scorer).shape == (2, 0)
if __name__ == "__main__":
unittest.main()