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

Potential Null pointer access in CMS_Conservative_increment_obj #47

Open
awen-li opened this issue May 14, 2021 · 3 comments
Open

Potential Null pointer access in CMS_Conservative_increment_obj #47

awen-li opened this issue May 14, 2021 · 3 comments

Comments

@awen-li
Copy link

awen-li commented May 14, 2021

Description

In CMS_Conservative_init, w is received from Python code.
Its size is not validated hence "self->table[i] = (CMS_CELL_TYPE *) calloc(self->width, sizeof(CMS_CELL_TYPE));" may fail , which cause the Null pointer.
self->table[i] would be accessed in CMS_Conservative_increment_obj, which make the Python crash down.

Steps/Code/Corpus to Reproduce

static int
CMS_VARIANT(_init)(CMS_TYPE *self, PyObject *args, PyObject *kwds)
{
    .........................
    for (i = 0; i < self->depth; i++)
    {
        self->table[i] = (CMS_CELL_TYPE *) calloc(self->width, sizeof(CMS_CELL_TYPE));
        printf ("[%d]self->table[%d] = %p \r\n", i, i, self->table[i]);
    }
    ...........................

Optional call-path: increment -> CMS_Log1024_increment -> CMS_Conservative_increment_obj

Expected Results

when w is set as an arbitrary number, Python can not crash down.

Actual Results

crash

Versions

the main branch

@awen-li awen-li changed the title Potential buffer-overflow in HyperLogLog_add of hill.c Potential Null pointer access in CMS_Conservative_increment_obj Sep 16, 2021
@awen-li
Copy link
Author

awen-li commented Sep 16, 2021

PoC:

from bounter import CountMinSketch

Cms = None
LogCounting = None

def setUp(LogCounting = None):
return CountMinSketch(1, width=2**31, depth=32, log_counting=LogCounting)

Cms = setUp ()
for i in range (0, 100):
Cms.increment('foo')
Cms.increment('bar')

print (Cms['foo'])
print (Cms['bar'])

Crash: Segmentation fault (core dumped)

@piskvorky
Copy link
Owner

@Daybreak2019 can you open a PR with a fix? Thanks!

@eric-wieser
Copy link

FWIW, this seems to have had a CVE opened against it: https://nvd.nist.gov/vuln/detail/CVE-2021-41497

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

3 participants