hardbyte / hardbyte/python-can

can.io Log Parsing Exceptions

Open
#822 1 comment 1 reaction 0 assignees View on GitHub
proposal
Dominant language
Python
Stars
1.6k
Forks
697
PR merge metrics
No merged PRs in 30d

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.