ascv / HyperLogLog

Fast HyperLogLog for Python.
MIT License
99 stars 19 forks source link

Segfaults if wrong type is passed to set_registers() #32

Closed ekimekim closed 4 years ago

ekimekim commented 4 years ago

I have a use case where I need to serialize a HLL then unserialize it later. I used registers() and set_registers() for this. However, due to the nature of the serialization, the registers were converted from a bytearray to a bytes. Not realising this, I attempted to call set_registers with this value, and my program promptly segfaulted due to this code:

    registers = PyByteArray_AsString((PyObject*) regs);
    self->use_cache = 0;

    int i;
    for (i = 0; i < self->size; i++) {
        self->registers[i] = registers[i];
    }

because the result of PyByteArray_AsString is not checked.

The expected behaviour when passed an inappropriate type would be a TypeError or other exception. Better yet would be to accept a bytes as input to this function.

ascv commented 4 years ago

Agreed. I will fix this in the next minor patch.

ascv commented 4 years ago

This should be fixed in #37 .

ascv commented 4 years ago

37 has been merged and uploaded to PyPi