Repository navigation
Conversation
A frame line that is cut short or holds invalid characters made _recv_internal() raise ValueError or IndexError from recv(), which ends a thread-based Notifier (hardbyte#1821). A line cut short after an even number of data digits decoded without error to fewer bytes than its DLC, because bytearray.fromhex() skips the CR terminator that falls into the data slice. Check that the decoded payload has the length the DLC asks for, and log and drop lines that do not parse, so reception continues with the next frame. Well-formed lines, including ones with trailing characters after the data, decode as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
slcanBus._recv_internal()now logs and drops a frame line that is cut short or contains invalid characters, instead of raising. A line with an odd number of data digits raisedValueError: non-hexadecimal number found in fromhex() arg at position N(the error in ValueError: non-hexadecimal number found in fromhex() arg at position 15 #1821), and an invalid identifier or DLC raisedValueErrororIndexError. None of these is aCanError, and on a thread-basedNotifierthe first one ends the receive thread, so valid frames that follow are never delivered.bytearray.fromhex()skips whitespace, so the\rterminator that fell into the data slice was ignored and the bus returned a message withdlc=8and only 2 or 3 data bytes. The new_decode_data()helper checks that the decoded payload has the length the DLC asks for, for classic and FD frames.UdpMulticastBusdatagrams that do not decode; onlyIndexErrorandValueErrorfrom the frame parsing are caught.Related Issues / Pull Requests
Type of Change
Checklist
tox).Additional Notes
Testing (Python 3.12, Linux container):
main:t1238112233445566778\r(15 of 16 data digits) raisesValueError: non-hexadecimal number found in fromhex() arg at position 15, andt12381\rraises at position 1. With aNotifierand aBufferedReader, a valid frame sent after such a line was never delivered: the receive thread ended andnotifier.exceptionheld theValueError. On this branch the same sequence delivers the valid frame and the thread keeps running.slcanBus.recv()onmainand on this branch. The 8 well-formed lines decode identically. The 10 malformed lines now returnNonewith a warning, wheremainraisedValueError/IndexErrorfor 7 of them and returned a message shorter than its DLC for the other 3 (dlc=8with 3 and 2 data bytes, and an FD frame withdlc=64and 5 data bytes).test_recv_malformed_frame_is_droppedhas 9 subtests that fail onmainand pass here.pytest test/test_slcan.py: 21 passed, 9 subtests passed.black --check,pylint can/interfaces/slcan.py(10.00/10) andmypy --python-version 3.12 can/interfaces/slcan.pypass. The fulltoxmatrix was not run.