Skip to content

Various parser crashes on random input #209

@jonathanslenders

Description

@jonathanslenders

Looks like there are multiple bugs in streams.py and screens.py that cause crashes when feeding random terminal input.

I was testing something, so I created a 100MB file with random content:

dd if=/dev/random of=bigfile bs=1024 count=102400

Then I was feeding this to the input of the stream. Multiple errors occured:

TypeError: insert_lines() got an unexpected keyword argument 'private' 
  File ".../site-packages/pyte/streams.py", line 205, in feed
    taking_plain_text = send(data[offset:offset + 1])
  File ".../site-packages/pyte/streams.py", line 213, in _send_to_parser
    return self._parser.send(data)
           ~~~~~~~~~~~~~~~~~^^^^^^
  File ".../site-packages/pyte/streams.py", line 347, in _parser_fsm
    params.append(min(int(current or 0), 9999))
                      ~~~^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '³'
  File ".../site-packages/pyte/streams.py", line 205, in feed
    taking_plain_text = send(data[offset:offset + 1])
  File ".../site-packages/pyte/streams.py", line 213, in _send_to_parser
    return self._parser.send(data)
           ~~~~~~~~~~~~~~~~~^^^^^^
  File ".../site-packages/pyte/streams.py", line 355, in _parser_fsm
    csi_dispatch[char](*params)
                                                                                                                                                                                                                                                  ~~~~~~~~~~~~~~~~~~^^^^^^^^^
TypeError: cursor_down() takes from 1 to 2 positional arguments but 3 were given

There were others. I don't think it makes sense to list them all. But I guess it would be good at some point to either run a fuzzer over the parser, or feed huge random files until it doesn't crash anymore on any input.

Note: this is not an hypothetical issue. Anyone can cat some/binary/file into the terminal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions