compenguy / ngrammatic

A rust crate providing fuzzy search/string matching using N-grams
MIT License
25 stars 7 forks source link

Unsoundly mark unsafe function as safe #13

Open safe4u opened 2 months ago

safe4u commented 2 months ago

Hi, thanks for your great contribution to this project first.

However, we have found a simple unsound problem in Corpus. The function Corpus::ngram_from_id is actually 'unsafe' since it does not validate the ngram_id is valid.

Suggestions

Here are some action choices we suggested:

  1. Mark this function as 'unsafe' so that it would pass the responsibility of ensuring the ngram_id to its caller.
  2. (recommended) Add assert! or at least debug_assert! macros before calling get_unchecked.