codeprentice-org / codeprentice-org/sniffpy

Crash on malformed input

Open
#42 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
7
Forks
7
PR merge metrics
No merged PRs in 30d

Description

Thank you for this work!

I discovered some poorly formed content that triggered an exception.

Example:
```python
import sniffpy
buf = (
b'\n\xef\xbb\xbf\n\n\n[...]\n\r\n'
)
sniffpy.sniff(buf)
```
produces:
```
Traceback (most recent call last):
File "", line 1, in
File "/share/github.com/codeprentice-org/sniffpy/sniffpy/sniff.py", line 205, in sniff
return sniff_unknown(resource, sniff_scriptable=not no_sniff)
File "/share/github.com/codeprentice-org/sniffpy/sniffpy/sniff.py", line 106, in sniff_unknown
mime_type = match.match_video_audio_type_pattern(resource)
File "/share/github.com/codeprentice-org/sniffpy/sniffpy/match.py", line 93, in match_video_audio_type_pattern
if is_mp3_pattern(resource):
File "/share/github.com/codeprentice-org/sniffpy/sniffpy/match.py", line 132, in is_mp3_pattern
if not match_mp3_header(resource, offset, parsed_values):
File "/share/github.com/codeprentice-org/sniffpy/sniffpy/utils.py", line 49, in match_mp3_header
parsed_values['layer'] = layer[0] >> 1
TypeError: 'int' object is not subscriptable
```
A few things are interesting to note about this content:
* Byte order mark follows a newline
* Line endings switch from `\n` to `\r\n` mid way
* Multiple `` tags
* Mismatched open/close tags

This sample was found on the web (by commoncrawl.org in 2017), though I have replaced large sections with "[...]" that were not significant to the crash.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.