hardbyte / hardbyte/python-can

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

Đang mở
#1,584 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Python
Star
1.6k
Fork
697
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### 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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.