Bug: Memory Amplification in PCAP Suricata Result Processing
Bug: Memory Amplification in PCAP Suricata Result Processing
Labels
bug, backend_simple
Location
integrations/pcap_analyzers/app.py::intercept_suricata_result (line 63)
Description
A single malformed JSON line in eve.json causes the entire remainder of the file to be read into memory, leading to potential memory exhaustion and DoS.
Code
def intercept_suricata_result(context, future: Future) -> None:
# ...
res["report"] = {"data": []}
with open(f"{directory}/eve.json", "r", encoding="utf_8") as fp:
for line in fp:
try:
res["report"]["data"].append(json.loads(line))
except json.JSONDecodeError as e:
logger.debug(e)
res["report"]["data"].append(fp.read()) # ❌ BUG: Reads entire remainder of file
Trigger
When parsing eve.json line-by-line (JSONL format), if any line fails to parse as JSON, the exception handler executes fp.read() which reads the entire remainder of the file into memory.
Observed Behavior
- First malformed JSON line encountered
json.JSONDecodeErrorraised- Exception handler calls
fp.read() - Entire remainder of file (potentially gigabytes) loaded into memory
- Process may crash or consume excessive memory
- Single malformed line can cause DoS via memory exhaustion
Expected Behavior
Skip the malformed line and continue processing subsequent valid lines. Log a warning for visibility.
Impact
- Memory exhaustion: Large/corrupted files cause process crashes
- DoS risk: Maliciously crafted input can exhaust system memory
- Resource amplification: Small input (single bad line) causes unbounded memory consumption
Security Implications
This is an input-triggered resource amplification vulnerability. An attacker could:
- Craft a PCAP file that generates a large
eve.json - Insert a single malformed JSON line early in the file
- Cause the entire large file to be read into memory
- Potentially crash the service or exhaust available memory
Proposed Fix
Replace the exception handler to skip malformed lines instead of reading the remainder:
except json.JSONDecodeError as e:
logger.warning(f"Skipping malformed JSON line in eve.json: {e}")
# Continue to next line - implicit skip
Complexity: < 5 LOC change
Why This Should Be Fixed
- ✅ Concrete bug: Unambiguous incorrect behavior
- ✅ Clear trigger: Single malformed JSON line
- ✅ Obvious bad behavior: Reading entire file on error
- ✅ Security-adjacent: DoS via memory exhaustion
- ✅ Trivial fix: Simple line skip with logging
- ✅ No opinion involved: Objectively wrong code
Additional Context
The eve.json file is in JSONL format (one JSON object per line). Each line should be parsed independently. There is no reason to read the remainder of the file when a single line fails to parse.
thanks, feel free to open a PR