gutierrezps / ESP32_I2C_Slave

I2C slave library for ESP32
GNU Lesser General Public License v2.1
81 stars 20 forks source link

Memory access violation on high data rates #5

Closed TylerBird closed 3 years ago

TylerBird commented 3 years ago

Thank you for your library. I used it in a project and stumbled upon an issue on high data rates. I found two problems in the WireSlaveRequest.cpp where memory is accessed in an array without range checking the index.

I solved the problem by changing the line while (unpacker.available()) in the bool WireSlaveRequest::request(uint8_t address) function to while ((unpacker.available()) && (rxIndex_ < UNPACKER_BUFFER_LENGTH)) and line if (lastStatus_ == PACKET_READ && rxIndex_ < rxLength_) in the int WireSlaveRequest::read() function to if (lastStatus_ == PACKET_READ && rxIndex_ < rxLength_ && (rxIndex_ < UNPACKER_BUFFER_LENGTH))

I will create a pull request with this fix.