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.
I have a use case where I need to serialize a HLL then unserialize it later. I used
registers()
andset_registers()
for this. However, due to the nature of the serialization, the registers were converted from abytearray
to abytes
. Not realising this, I attempted to callset_registers
with this value, and my program promptly segfaulted due to this code: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.