hardbyte / hardbyte/python-can
can.BLFReader: Stuck in infinite loop when obj_size = 0.
- Lingua principale
- Python
- Stelle
- 1.6k
- Fork
- 697
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
### 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
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.