hardbyte / hardbyte/python-can

can.io Log Parsing Exceptions

Ouverte
#822 1 commentaire 1 réaction 0 personnes assignées Voir sur GitHub
proposal
Langage dominant
Python
Étoiles
1.6k
Forks
697
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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)
```

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.