Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/clusterfuzz/_internal/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from clusterfuzz._internal.config import local_config
from clusterfuzz._internal.metrics import logs
from clusterfuzz._internal.system import environment
from clusterfuzz._internal.system import shell

try:
import psutil
Expand Down Expand Up @@ -658,6 +659,17 @@ def read_data_from_file(file_path, eval_data=True, default=None):
return None


def read_data_from_file_and_remove(file_path, eval_data=False, default=None):
"""Reads file content and removes the file after read"""
if not file_path or not os.path.exists(file_path):
return default

try:
return read_data_from_file(file_path, eval_data=eval_data, default=default)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we still call remove_file if this throws an error?

finally:
shell.remove_file(file_path)


def remove_prefix(string, prefix):
"""Strips the prefix from a string."""
if string.startswith(prefix):
Expand Down
60 changes: 60 additions & 0 deletions src/clusterfuzz/_internal/bot/testcase_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import base64
import collections
import dataclasses
import datetime
import os
import re
Expand Down Expand Up @@ -356,6 +357,65 @@ class Crash(
fields."""


@dataclasses.dataclass
class FuzzerRunOutputData:
"""Output metadata for a single fuzzer run stored in memory or a temp file."""
_output: str | bytes | None = None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would document that you expect _output and _file_path to be a oneof

_file_path: str | None = None
crash_path: str | None = None
return_code: int = 0
log_time: datetime.datetime | None = None

@classmethod
def from_file_path(cls,
file_path: str,
crash_path: str | None = None,
return_code: int = 0,
log_time: datetime.datetime | None = None):
return cls(
_file_path=file_path,
crash_path=crash_path,
return_code=return_code,
log_time=log_time)

@classmethod
def from_memory(cls,
output: str | bytes,
crash_path: str | None = None,
return_code: int = 0,
log_time: datetime.datetime | None = None):
return cls(
_output=output,
crash_path=crash_path,
return_code=return_code,
log_time=log_time)

def get_output(self) -> str | None:
"""Reads or decodes the fuzzer output text."""
if self._file_path:
if not os.path.exists(self._file_path):
return None
output = utils.read_data_from_file_and_remove(

@IvanBM18 IvanBM18 Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deletes the files because output files are meant to be temp files that allows us to more easily capture the fuzzer's log output

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, this probably answers my previous comment.

self._file_path, eval_data=False)
return None if output is None else output.decode(
'utf-8', errors='replace')

if not self._output:
return None

if isinstance(self._output, bytes):
return self._output.decode('utf-8', errors='replace')

return self._output


@dataclasses.dataclass
class TestcaseRunResult:
"""Result of a testcase execution queued for processing."""
crash: Crash | None = None
fuzzer_run_output_data: FuzzerRunOutputData | None = None


def get_resource_paths(output):
"""Read the urls from the output."""
resource_paths = set()
Expand Down
Loading