hardbyte / hardbyte/python-can

can.io Log Parsing Exceptions

Đang mở
#822 1 bình luận 1 reaction 0 người được giao Xem trên GitHub
proposal
Ngôn ngữ chính
Python
Star
1.6k
Fork
697
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.