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

Memory safety in public API #1029

Open
zh217 opened this issue Jan 31, 2023 · 0 comments
Open

Memory safety in public API #1029

zh217 opened this issue Jan 31, 2023 · 0 comments

Comments

@zh217
Copy link

zh217 commented Jan 31, 2023

Hi, thanks for the great project! I noticed that networkit does not check for out of bound array access for many operations in the C++ code, and this problem persists in the Python API. For example:

In [1]: import networkit as nk

In [2]: g = nk.Graph(n=10)

In [3]: g.degree(14)
Out[3]: 17734729476854972094

In [4]: g.degree(10000000000000)
[1]    83923 segmentation fault  ipython

If networkit is used in an environment that accepts user inputs and the calling code does not check for the validity of the input either, this could lead to security vulnerabilities.

Is this behaviour intentional? I don't think it should be, since out-of-bound access in C++ is UB, and even if there is a strong reason, I think it should be much better documented, with scary warnings for the casual user. If no, is there any plan to fix it? Simply replacing calls like v[i] with v.at(i) will transform these UB into runtime exceptions, which I think is sufficient. On modern CPUs bound checking is almost free, so omitting them usually does not make code run faster.

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

No branches or pull requests

1 participant