Skip to content

Commit 9db0b4e

Browse files
committed
Add Atheris fuzz target for the SSE decoder
1 parent 08f8998 commit 9db0b4e

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,14 @@ jobs:
9494
with:
9595
name: dist
9696
path: dist/
97+
98+
fuzz:
99+
name: Fuzz SSE decoder
100+
runs-on: ubuntu-latest
101+
steps:
102+
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
103+
- uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
104+
with:
105+
python-version: "3.12"
106+
- run: uv sync --locked
107+
- run: uv run --with atheris python fuzz/fuzz_sse.py -max_total_time=60

‎fuzz/fuzz_sse.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Atheris fuzz target for the server-sent-events decoder.
2+
3+
Run with: uv run --with atheris python fuzz/fuzz_sse.py
4+
"""
5+
6+
import sys
7+
8+
import atheris
9+
10+
with atheris.instrument_imports():
11+
from opencode._streaming import _Decoder, _LineSplitter
12+
13+
14+
def test_one_input(data: bytes) -> None:
15+
"""Feed arbitrary text through the line splitter and SSE decoder."""
16+
text = atheris.FuzzedDataProvider(data).ConsumeUnicodeNoSurrogates(len(data))
17+
splitter = _LineSplitter()
18+
decoder = _Decoder()
19+
for line in splitter.feed(text) + splitter.flush():
20+
decoder.feed_line(line)
21+
22+
23+
if __name__ == "__main__":
24+
atheris.Setup(sys.argv, test_one_input)
25+
atheris.Fuzz()

0 commit comments

Comments
 (0)