Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB Tx buffer overflow undetected #6

Open
Nakakiyo092 opened this issue Dec 24, 2024 · 0 comments · May be fixed by #8
Open

USB Tx buffer overflow undetected #6

Nakakiyo092 opened this issue Dec 24, 2024 · 0 comments · May be fixed by #8

Comments

@Nakakiyo092
Copy link

Nakakiyo092 commented Dec 24, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant