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

Unsound problems in pleco_engine crate #158

Open
safe4u opened this issue Jul 7, 2024 · 1 comment · May be fixed by #159
Open

Unsound problems in pleco_engine crate #158

safe4u opened this issue Jul 7, 2024 · 1 comment · May be fixed by #159

Comments

@safe4u
Copy link

safe4u commented Jul 7, 2024

Hi, thanks for your contribution to this great engine.

However, we have found some unsound problems in the crate pleco_engine.
For example, insert_score_depth and insert_score use get_unchecked_mut to access target RootMove without boundary checking for performance consideration.
These functions are actually unsafe since they ask the caller to guarantee the index is in-bound and the compiler fails to check this.

It is certainly ok to mark the unsafe functions as safe and use them with care in 'pleco'.
But considering the crate pleco_engine is available in crates.io and these functions are public, we think it's still necessary to make these functions more sound.

Suggestions

Here are some action choices we suggested:

  1. Mark these functions as 'unsafe' which would lead to large code changes.
  2. (recommended) Add assert! or at least debug_assert! macros to validate that the index is in-bound.
@chase-manning
Copy link
Contributor

Thanks for the feedback! I would lean towards option 2. Please feel free to raise a PR for this 😃

@safe4u safe4u linked a pull request Jul 7, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants