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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ stricter subset of Keep a Changelog).
- Command output shown in error, timeout and interrupt panels is now cut to its last 100 lines so a noisy CRS no longer floods the terminal. For `oss-crs run`, the notice about omitted lines also prints the run's logs directory where the full output is saved.

### Added
- Target compatibility validation in CRS (`is_supported_target`): validates target language, sanitizer, architecture, and fuzzing engine against `supported_target` declared in `crs.yaml`, skipping incompatible targets gracefully during `build-target` and `is_target_built`.
- `oss-crs list-harnesses --fuzz-proj-path <PATH_TO_PROJ>` — builds an OSS-Fuzz project through its default Docker compile path and lists its runnable fuzz harnesses, reusing cached build artifacts until the project inputs or repository HEAD change.
- `--extra-ca-certs` flag, `extra_ca_certs` compose key, and `OSS_CRS_EXTRA_CA_CERTS` env var — trust additional CA certificates for LLM endpoints whose certificate chains to an internal CA. The PEM is merged with the public root store and mounted read-only at `/etc/oss-crs/ca` in the internal LiteLLM proxy and every CRS run container, with `SSL_CERT_FILE`, `REQUESTS_CA_BUNDLE`, `CURL_CA_BUNDLE` and `NODE_EXTRA_CA_CERTS` pointed at it; the host-side external-LiteLLM `/models` check uses it too and now names this setting when a TLS verification error is what failed. Precedence is flag, then compose key, then env var. Does not affect `docker pull`/`docker build`, which use the Docker daemon's trust store. No option to skip verification is added.
- Run-phase exchange artifact inputs and forwarding: generated `oss-crs run` flags for `--pov/--pov-dir`, `--seed-dir`, `--bug-candidate/--bug-candidate-dir`, `--report/--report-dir`, and `--patch/--patch-dir`; `libCRS fetch patch` support via `FETCH_DIR/patches`; and `--forward-artifacts [<run-id>[,<run-id>...]]` to forward prior run artifacts into the new run's `FETCH_DIR`. Forwarding searches sibling compose-hash workdirs, prompts when a run ID maps to multiple source target/harness/sanitizer combinations, prefers processed POVs/seeds when available, and records provenance in `FORWARDED_ARTIFACTS.json`. Passing bare `--forward-artifacts` in an interactive terminal prompts with prior artifact-producing runs for the same target project across any CRS compose hash. Omitting the flag does not forward artifacts. `--diff` remains the special delta-mode reference diff input.
Expand Down
4 changes: 2 additions & 2 deletions PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ These items are the highest-priority incomplete features, critical for making en

| Item | Status | Notes |
|---|---|---|
| `supported_target` validation | TODO in code | Properly check CRS-declared supported languages, sanitizers, and architectures against the actual target |
| Warn vs. error policy | TODO in code | Decide whether a compatibility mismatch should warn or abort |
| `supported_target` validation | ✅ Implemented | Validates target language, sanitizer, architecture, and engine against CRS supported_target |
| Warn vs. error policy | ✅ Implemented | Gracefully skips incompatible targets during build-target while allowing other CRSs to run |

### Validation Improvements

Expand Down
35 changes: 34 additions & 1 deletion oss_crs/src/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,42 @@ def __build_run_image(
)

def __is_supported_target(self, target: Target) -> bool:
_ = target
"""Return True only when *target* is compatible with this CRS.

Each dimension of ``self.config.supported_target`` is a set of enum
values. ``Target`` stores the same attributes as plain strings
(e.g. ``target.language == "c"``), so we compare against the enum values.

Returns False when any of the following mismatches is detected:
* ``target.language`` not in ``supported_target.language``
* ``target.sanitizer`` not in ``supported_target.sanitizer``
* ``target.architecture`` not in ``supported_target.architecture``
* ``target.engine`` not in ``supported_target.fuzzing_engine``
"""
st = self.config.supported_target

supported_languages = {e.value for e in st.language}
if target.language not in supported_languages:
return False

supported_sanitizers = {e.value for e in st.sanitizer}
if target.sanitizer not in supported_sanitizers:
return False

supported_architectures = {e.value for e in st.architecture}
if target.architecture not in supported_architectures:
return False

supported_engines = {e.value for e in st.fuzzing_engine}
if target.engine not in supported_engines:
return False

return True

def is_supported_target(self, target: Target) -> bool:
"""Public alias for __is_supported_target."""
return self.__is_supported_target(target)

def build_target(
self,
target: Target,
Expand Down
335 changes: 335 additions & 0 deletions oss_crs/tests/unit/test_crs_supported_target.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,335 @@
# SPDX-License-Identifier: MIT
"""Unit tests for CRS target compatibility validation (supported_target)."""

import textwrap
from dataclasses import dataclass
from pathlib import Path

from oss_crs.src.config.crs_compose import CRSEntry, CRSSource
from oss_crs.src.crs import CRS
from oss_crs.src.ui import TaskResult
from oss_crs.src.workdir import WorkDir


@dataclass
class _MockTarget:
name: str = "mock-target"
language: str = "c"
sanitizer: str = "address"
architecture: str = "x86_64"
engine: str = "libfuzzer"


class _CaptureProgress:
"""Mock MultiTaskProgress to capture scheduled tasks without execution."""

def __init__(self):
self.tasks: list[tuple[str, object]] = []

def add_task(self, name, func):
self.tasks.append((name, func))

def run_added_tasks(self):
return TaskResult(success=True)


def _make_crs(
tmp_path: Path,
supported_target_yaml: str | None = None,
crs_name: str = "test-crs",
) -> CRS:
crs_root = tmp_path / crs_name
(crs_root / "oss-crs").mkdir(parents=True, exist_ok=True)

if supported_target_yaml is None:
supported_target_yaml = textwrap.dedent(
"""\
supported_target:
mode: [full]
language: [c]
sanitizer: [address]
architecture: [x86_64]
fuzzing_engine: [libfuzzer]
"""
)

crs_yaml_content = (
textwrap.dedent(
f"""\
name: {crs_name}
type: [bug-finding]
version: 1.0.0
prepare_phase:
hcl: docker-bake.hcl
crs_run_phase:
fuzzer:
dockerfile: oss-crs/fuzzer.Dockerfile
"""
)
+ supported_target_yaml
)

(crs_root / "oss-crs" / "crs.yaml").write_text(crs_yaml_content)

resource = CRSEntry(
cpuset="0-1",
memory="2G",
source=CRSSource(local_path=str(crs_root)),
)
return CRS(
name=crs_name,
crs_path=crs_root,
work_dir=WorkDir(tmp_path / "work"),
resource=resource,
crs_compose_env=None,
)


def test_is_supported_target_all_matching(tmp_path: Path) -> None:
crs = _make_crs(tmp_path)
target = _MockTarget(
language="c",
sanitizer="address",
architecture="x86_64",
engine="libfuzzer",
)
assert crs.is_supported_target(target) is True


def test_is_supported_target_language_mismatch(tmp_path: Path) -> None:
crs = _make_crs(tmp_path)
target = _MockTarget(language="jvm")
assert crs.is_supported_target(target) is False


def test_is_supported_target_sanitizer_mismatch(tmp_path: Path) -> None:
crs = _make_crs(tmp_path)
target = _MockTarget(sanitizer="memory")
assert crs.is_supported_target(target) is False


def test_is_supported_target_architecture_mismatch(tmp_path: Path) -> None:
crs = _make_crs(tmp_path)
target = _MockTarget(architecture="aarch64")
assert crs.is_supported_target(target) is False


def test_is_supported_target_engine_mismatch(tmp_path: Path) -> None:
crs = _make_crs(tmp_path)
target = _MockTarget(engine="afl")
assert crs.is_supported_target(target) is False


def test_is_supported_target_multiple_allowed_values(tmp_path: Path) -> None:
supported_yaml = textwrap.dedent(
"""\
supported_target:
mode: [full, delta]
language: [c, c++]
sanitizer: [address, undefined]
architecture: [x86_64, i386]
fuzzing_engine: [libfuzzer, afl]
"""
)
crs = _make_crs(tmp_path, supported_target_yaml=supported_yaml)

# All these variations should match
assert (
crs.is_supported_target(
_MockTarget(
language="c",
sanitizer="address",
architecture="x86_64",
engine="libfuzzer",
)
)
is True
)
assert (
crs.is_supported_target(
_MockTarget(
language="c++", sanitizer="undefined", architecture="i386", engine="afl"
)
)
is True
)

# Variations with unlisted values should be rejected
assert (
crs.is_supported_target(
_MockTarget(
language="rust",
sanitizer="address",
architecture="x86_64",
engine="libfuzzer",
)
)
is False
)
assert (
crs.is_supported_target(
_MockTarget(
language="c",
sanitizer="memory",
architecture="x86_64",
engine="libfuzzer",
)
)
is False
)
assert (
crs.is_supported_target(
_MockTarget(
language="c",
sanitizer="address",
architecture="aarch64",
engine="libfuzzer",
)
)
is False
)
assert (
crs.is_supported_target(
_MockTarget(
language="c",
sanitizer="address",
architecture="x86_64",
engine="honggfuzz",
)
)
is False
)


def test_is_supported_target_uses_schema_defaults(tmp_path: Path) -> None:
"""When sanitizer, architecture, or fuzzing_engine are omitted, default schema values apply."""
minimal_supported_yaml = textwrap.dedent(
"""\
supported_target:
mode: [full]
language: [c]
"""
)
crs = _make_crs(tmp_path, supported_target_yaml=minimal_supported_yaml)

# Defaults include address sanitizer, x86_64 architecture, and libfuzzer engine
assert (
crs.is_supported_target(
_MockTarget(
language="c",
sanitizer="address",
architecture="x86_64",
engine="libfuzzer",
)
)
is True
)

# Defaults include ubsan (undefined) as well
assert (
crs.is_supported_target(
_MockTarget(
language="c",
sanitizer="undefined",
architecture="x86_64",
engine="libfuzzer",
)
)
is True
)

# Language is still strictly checked
assert (
crs.is_supported_target(
_MockTarget(
language="python",
sanitizer="address",
architecture="x86_64",
engine="libfuzzer",
)
)
is False
)


def test_build_target_skips_unsupported_target(tmp_path: Path) -> None:
crs = _make_crs(tmp_path, crs_name="my-crs")
incompatible_target = _MockTarget(name="java-project", language="jvm")
progress = _CaptureProgress()

result = crs.build_target(
target=incompatible_target,
target_base_image="base:latest",
progress=progress,
build_id="build-1",
sanitizer="address",
)

assert result.success is True
assert (
"Skipping target java-project for CRS my-crs as it is not supported."
in result.output
)
# No build tasks should be scheduled
assert len(progress.tasks) == 0


def test_is_target_built_skips_unsupported_target(tmp_path: Path) -> None:
# Set up a CRS with a target_build_phase
crs_root = tmp_path / "crs-with-build"
(crs_root / "oss-crs").mkdir(parents=True, exist_ok=True)
crs_yaml_content = textwrap.dedent(
"""\
name: crs-with-build
type: [bug-finding]
version: 1.0.0
prepare_phase:
hcl: docker-bake.hcl
target_build_phase:
builds:
- name: compile
dockerfile: oss-crs/compile.Dockerfile
outputs: [binary]
crs_run_phase:
fuzzer:
dockerfile: oss-crs/fuzzer.Dockerfile
supported_target:
mode: [full]
language: [c]
sanitizer: [address]
architecture: [x86_64]
fuzzing_engine: [libfuzzer]
"""
)
(crs_root / "oss-crs" / "crs.yaml").write_text(crs_yaml_content)

resource = CRSEntry(
cpuset="0-1",
memory="2G",
source=CRSSource(local_path=str(crs_root)),
)
crs = CRS(
name="crs-with-build",
crs_path=crs_root,
work_dir=WorkDir(tmp_path / "work"),
resource=resource,
crs_compose_env=None,
)

incompatible_target = _MockTarget(name="rust-project", language="rust")
progress = _CaptureProgress()

result = crs.is_target_built(
target=incompatible_target,
target_base_image="base:latest",
progress=progress,
build_id="build-1",
sanitizer="address",
)

assert result.success is True
assert (
"Skipping target rust-project for CRS crs-with-build as it is not supported."
in result.output
)
assert len(progress.tasks) == 0