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 issues with HashTable when resizing #32907

Open
Mibu287 opened this issue Mar 22, 2020 · 2 comments
Open

Memory issues with HashTable when resizing #32907

Mibu287 opened this issue Mar 22, 2020 · 2 comments
Labels
Bug Internals Related to non-user accessible pandas implementation

Comments

@Mibu287
Copy link

Mibu287 commented Mar 22, 2020

As I read file pandas/_libs/src/klib/khash.h, I notice lines 226, 227 in macro kh_resize_##name (source)

h->keys = (khkey_t*)realloc(h->keys, new_n_buckets * sizeof(khkey_t)); \
if (kh_is_map) h->vals = (khval_t*)realloc(h->vals, new_n_buckets * sizeof(khval_t)); \

If realloc fail in either statement, it set h->keys or h->vals to NULL and leak original pointer value. Any attempt to deref new value of h->keys or h->vals will lead to undefined behaviors.

Should we assign result of memory allocation to a temporary variable and perform check before reassign to HashTable's internal data?

@jbrockmendel
Copy link
Member

cc @WillAyd

@WillAyd
Copy link
Member

WillAyd commented Sep 2, 2020

Yea I think that makes sense. This code is vendored from klib so worth checking if it's been patched upstream first otherwise can do here.

@Dr-Irv Dr-Irv added Bug Internals Related to non-user accessible pandas implementation labels Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Internals Related to non-user accessible pandas implementation
Projects
None yet
Development

No branches or pull requests

4 participants