hardbyte / hardbyte/python-can

can.io Log Parsing Exceptions

未关闭
#822 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
proposal
主要语言
Python
星标
1.6k
派生
697
PR 合并指标
30 天内没有已合并 PR

描述

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

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。