hardbyte / hardbyte/python-can

can.io Log Parsing Exceptions

Abierto
#822 1 comentario 1 reacción 0 asignados Ver en GitHub
proposal
Lenguaje dominante
Python
Estrellas
1.6k
Forks
697
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

I've been playing around with AFL lately to see what sorts of things I can break. I threw together a fuzzer harness for fun using `py-afl-fuzz` and pointed it at a few of the `can.io` modules, in the hopes of checking any assumptions we were making about valid input when parsing.

What is the expected behaviour when parsing log files? Is it that `python-can` should only raise Exceptions that it itself is raising?

For example, in a lot of places, we assume that we can do `int(val)`, despite `val` potentially being an invalid literal. As such, we currently raise `ValueError` when we can't parse these. Do we expect to handle situations like this and raise a separate `Exception` saying that the file format was invalid?

As a data point, `json` does the following when an invalid JSON object is passed to `json.load`:

```
→ TITANIC@~ $ python
Python 3.8.0 (default, Dec 1 2019, 19:49:20)
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> from io import StringIO
>>> json.load(StringIO("{"))
Traceback (most recent call last):
File "", line 1, in
File "/home/karl/.pyenv/versions/3.8.0/lib/python3.8/json/__init__.py", line 293, in load
return loads(fp.read(),
File "/home/karl/.pyenv/versions/3.8.0/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/home/karl/.pyenv/versions/3.8.0/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/home/karl/.pyenv/versions/3.8.0/lib/python3.8/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
```

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.