Skip to content

Reader.peek(index) throws IndexError when the stream ends, instead of returning '\0' #904

@coco1629

Description

@coco1629

When the requested index exceeds the available data, update() cannot add enough data to the buffer, causing the parser to crash with an IndexError. The expected behavior is to return a '\0' terminator or raise a controlled ReaderError exception.

poc

obj = yaml.loader.Loader('abc')
ret = obj.peek(4)

trace:

Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.9/site-packages/yaml/reader.py", line 89, in peek
    return self.buffer[self.pointer+index]
IndexError: string index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/PyRTFuzz/check/failed/seeds_yaml5/yaml.reader.Reader.peek/1#yaml#reader#Reader#peek.py", line 33, in <module>
    RunFuzzer('abc')
  File "/root/PyRTFuzz/check/failed/seeds_yaml5/yaml.reader.Reader.peek/1#yaml#reader#Reader#peek.py", line 30, in RunFuzzer
    output = dc.demoFunc(x)
  File "/root/PyRTFuzz/check/failed/seeds_yaml5/yaml.reader.Reader.peek/1#yaml#reader#Reader#peek.py", line 24, in demoFunc
    ret = obj.peek(4)
  File "/root/anaconda3/lib/python3.9/site-packages/yaml/reader.py", line 92, in peek
    return self.buffer[self.pointer+index]
IndexError: string index out of range

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