Stacktrace on badly formed CAN_ErrorFrame (?)
還沒有人認領這個 Issue。
評估
研究方向
從 can/io/mf4.py 約第 410 行開始,這裡使用回報的 DataLength 對 CAN_ErrorFrame.DataBytes 進行索引。使用 Kvaser MF4 檔案重現問題,並在該存取之前檢查 CAN_ErrorFrame.DataBytes 的形狀和值。完成標準是 can.LogReader 消費錯誤訊框時不引發 IndexError,且提供的迭代能正常運作。
由索引模型根據 Issue 內容生成。
描述
Describe the bug
We have an MF4 file from Kvaser that causes the following stack trace when run:
Traceback (most recent call last):
File "load.py", line 43, in <module>
sys.exit(main(args))
File "load.py", line 27, in main
for msg in can.LogReader(args.mf4_file):
File "/home/john/.pyenv/versions/3.8.20/lib/python3.8/heapq.py", line 373, in merge
value = next()
File "/home/john/tmp/keep_1y/python-can/can/io/mf4.py", line 410, in __iter__
kv["data"] = data["CAN_ErrorFrame.DataBytes"][i][
IndexError: invalid index to scalar variable.
The test code is essentially:
for msg in can.LogReader(mf4_file):
if msg.is_error_frame:
count["error"] += 1
else:
count["other"] += 1
I put some debug at site of the error (line 407 of can/io/mf4.py):
data_length=4
data["CAN_ErrorFrame.DataBytes"][i]=16777216
2^24?
To Reproduce
I was unable to create a file with python-can with the error data.
Expected behavior
No crash. :)
Additional context
OS and version: Linux
Python version: 3.8.20
python-can version: 654a02ae 2024-11-28 | Changelog for v4.5.0 (#1897) (HEAD -> main, origin/main, origin/HEAD)
python-can interface/s (if applicable): None
Traceback and logs
If I make this hack it consumes the error frame:
diff --git a/can/io/mf4.py b/can/io/mf4.py
index 4f5336b4..099395b4 100644
--- a/can/io/mf4.py
+++ b/can/io/mf4.py
@@ -405,9 +405,9 @@ class MF4Reader(BinaryIOMessageReader):
and "CAN_ErrorFrame.DataBytes" in names
):
data_length = int(data["CAN_ErrorFrame.DataLength"][i])
- kv["data"] = data["CAN_ErrorFrame.DataBytes"][i][
+ kv["data"] = data["CAN_ErrorFrame.DataBytes"][i].tobytes()[
:data_length
- ].tobytes()
+ ]
yield Message(**kv)
- 主要語言
- Python
- 星號
- 1.6k
- 分支
- 700
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
hardbyte/python-can 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 88/100
hardbyte/python-can#2103 ·
-
Unhashable type for Systec interface errors可能已有人在做 @giri256 於 81 天前認領。 未關閉bug
難度 1/5 1 小時以內 新手友好度 78/100
hardbyte/python-can#2077 · 1 則留言 · 1 個 reaction ·
-
bug
難度 1/5 1 小時以內 新手友好度 68/100
hardbyte/python-can#1922 · 1 個 reaction ·
-
Make socket binding exceptions more debugable可能已有人在做 @vonpanda 於 9 天前認領。 未關閉enhancement
難度 3/5 1-2 天 新手友好度 75/100
hardbyte/python-can#2104 ·
-
enhancement
難度 5/5 一週以上 新手友好度 30/100
hardbyte/python-can#2102 ·
查看 hardbyte/python-can 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 75/100
common-workflow-language/cwl-utils#477 ·
維護者通常 1 天內回覆
-
Add dependabot未關閉feat
難度 2/5 1 小時以內 新手友好度 72/100
open-nudge/opentemplate#204 ·
維護者通常 1 天內回覆
-
github-stale-ci-pr-closer: KV state is double-wrapped, never persists, and hits the depth-32 limit可能已有人在做 @VascoSch92 今天認領。 未關閉priority:medium ready-for-dev
難度 2/5 1-3 小時 新手友好度 72/100
OpenHands/extensions#781 ·
維護者通常 1 天內回覆
-
bug good first issue
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
curriculum documentation quality
難度 2/5 1-3 小時 新手友好度 78/100
githubnext/gh-aw-workshop#4638 ·
維護者通常 1 天內回覆