hardbyte / hardbyte/python-can

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

Abierto
#1,584 0 comentarios 0 reacciones 0 asignados Ver en GitHub
bug
Lenguaje dominante
Python
Estrellas
1.6k
Forks
697
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.