hardbyte / hardbyte/python-can

can.BLFReader: Stuck in infinite loop when obj_size = 0.

オープン
#1,584 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug
主要言語
Python
スター
1.6k
フォーク
697
PR マージ指標
30日以内にマージされた PR はありません

説明

### Describe the bug
When a BLF file that may have errors is processed by can.BLFReader, it is possible that the script will get stuck in an infinite loop when the header "obj_size" = 0. There is no error handling if this is the case and the script will remain forever running.

### To Reproduce
Within blf.py, the following section does not have error handling when "obj_size" = 0:

```
while True:
self._pos = pos
# Find next object after padding (depends on object type)
try:
pos = data.index(b"LOBJ", pos, pos + 8)
except ValueError:
if pos + 8 > max_pos:
# Not enough data in container
return
raise BLFParseError("Could not find next object") from None
header = unpack_obj_header_base(data, pos)
# print(header)
signature, _, header_version, obj_size, obj_type = header
if signature != b"LOBJ":
raise BLFParseError()
```

If it is changed to the following, we can prevent infinite loop when obj_size = 0:
```
while True:
self._pos = pos
# Find next object after padding (depends on object type)
try:
pos = data.index(b"LOBJ", pos, pos + 8)
except ValueError:
if pos + 8 > max_pos:
# Not enough data in container
return
raise BLFParseError("Could not find next object") from None
header = unpack_obj_header_base(data, pos)
# print(header)
signature, _, header_version, obj_size, obj_type = header
if signature != b"LOBJ":
raise BLFParseError()
**if obj_size == 0:
**raise BLFParseError("Object size = 0, issue with file") from None****
```

### Expected behavior
When the obj_size = 0, the script should not remain in infinite loop. An error flag should be raised to indicate something is wrong with the file.

### Additional context

OS and version: Windows 10
Python version: 3.11.2
python-can version: 4.1.0

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。