hardbyte / hardbyte/python-can

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

未关闭
#1,584 0 条评论 0 个 reaction 已指派 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 摘要。