openpilot icon indicating copy to clipboard operation
openpilot copied to clipboard

Fix length of ArrayPtr in handle_encoder_msg

Open jakepoz opened this issue 3 years ago • 1 comments

Description I was just reading the code for loggerd.cc and it appears that the ArrayPtr created from the received cereal message has the wrong size. It should be in 64bit capnp-words, not bytes.

Verification I don't own a Comma 3, but I'm using cereal and some of this code in my own robotics project and I was getting crashes.

jakepoz avatar Oct 14 '22 17:10 jakepoz

It is true that the correct size should be msg->getSize() / sizeof(capnp::word)). but I suspect that your crash is because the data (msg->getData()) is not word aligned at all. FlatArrayMessageReader will read the first few bytes to determine the length of the message to read, if the start address is word aligned and the length data in table is correct, it will stop read at FlatArrayMessageReader::getEnd(). sending a larger size to it should not cause a crash.

A safer way might be to use AlignedBuffer (messaging.h) to make sure the buffer is word aligned.

deanlee avatar Oct 16 '22 19:10 deanlee

Yeah, I believe the crash was only showing up because there was corrupt data in the message.

jakepoz avatar Oct 17 '22 19:10 jakepoz