canable2-fw
canable2-fw copied to clipboard
USB Tx buffer overflow undetected
Description of the bug
CANable fails to detect a USB transmit buffer overflow most of the time. Message is lost without error.
To reproduce
I made a script to produce a buffer overflow, which is provided at the end of this post.
It sends 200 V commands at once then checks the reply.
I got only 154 replies and one of them was corrupted as follows:
...
b158aa7 github.com/normaldotcom/canable2-fw[CR]
b158aa7 github.com/normaldotcom/canable2-fw[CR]
ldotcom/canable2-fw[CR]
b158aa7 github.com/normaldotcom/canable2-fw[CR]
b158aa7 github.com/normaldotcom/canable2-fw[CR]
...
It is obvious some of data was lost.
However the result of E command showed no error.
CANable Error Register: 0
Expected behavior
Buffer overflow in this case is quite normal, but CANable should detect it and notify of the error.
Script to produce buffer overflow
overflow.py
import time
import serial
# connect to canable
# device name should be changed
canable = serial.Serial('/dev/ttyACM0', timeout=1)
# send a lot of command without receiving data
# maybe 200 is not enough depending on environment
for idx in range(0, 200):
canable.write('V\r'.encode())
# recieve all reply
rx_data = b''
while True:
time.sleep(1)
tmp = canable.read_all()
rx_data = rx_data + tmp
if len(tmp) == 0:
break
# print reply
rx_data = rx_data.replace('\r'.encode(), '[CR]\n'.encode())
print(rx_data.decode())
# check error
canable.write('E\r'.encode())
time.sleep(1)
print(canable.read_all().decode())
canable.close()
My environment:
Ubuntu 24.04.1 LTS
Python 3.12.3
pyserial 3.5
This will not happen anymore with the new Slcan 2.5 firmware https://netcult.ch/elmue/CANable%20Firmware%20Update