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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ stricter subset of Keep a Changelog).

## [Unreleased]

### Fixed

- Exclude hidden files/directories and symlinks when copying artifact inputs and forwarding prior-run artifacts in `crs-compose`.

### Changed

- Ignore symlinks and hidden bookkeeping files when copying artifact inputs and forwarding artifacts into the exchange directory in `CRSCompose`.
- Auditing CRS type: does not require a target harness and produces bug-candidates
- `oss-crs export` and `oss-crs import` commands — imports/exports docker images/CRS source code to transfer to another host.
- Run-phase modules now default to `target_dependent: true`, so their images are built once per target during `build-target`. Set `target_dependent: false` for modules that can be built once during `prepare`.
Expand Down
16 changes: 15 additions & 1 deletion oss_crs/src/crs_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,14 @@ def _forwarded_artifact_names(
names.add(spec.name)
return names

@staticmethod
def _ignore_hidden_and_symlinks(directory: str, names: list[str]) -> set[str]:
return {
name
for name in names
if name.startswith(".") or os.path.islink(os.path.join(directory, name))
}

def _copy_forward_artifact_sources(
self,
*,
Expand All @@ -1653,6 +1661,7 @@ def _copy_forward_artifact_sources(
dst_dir,
dirs_exist_ok=True,
copy_function=shutil.copy2,
ignore=self._ignore_hidden_and_symlinks,
)
copied_counts[artifact_dir] = count
records.append(
Expand Down Expand Up @@ -2483,12 +2492,17 @@ def _copy_artifact_input(
dst_dir,
dirs_exist_ok=True,
copy_function=shutil.copy2,
ignore=self._ignore_hidden_and_symlinks,
)
else:
# Flat types (povs, seeds) are hash-named files; subdirectories
# would break the consumers' flat-listing assumption.
for f in artifact_input.directory.iterdir():
if f.is_file():
if (
not f.name.startswith(".")
and not f.is_symlink()
and f.is_file()
):
shutil.copy2(f, dst_dir / f.name)

def copy_artifact_inputs(progress: MultiTaskProgress) -> TaskResult:
Expand Down
113 changes: 113 additions & 0 deletions oss_crs/tests/unit/test_directed_inputs_behavior.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# SPDX-License-Identifier: MIT
from pathlib import Path

import pytest

import oss_crs.src.crs_compose as crs_compose_module
from oss_crs.src.crs_compose import ArtifactInput, CRSCompose, ForwardArtifactSource
from oss_crs.src.target import Target
Expand Down Expand Up @@ -622,3 +624,114 @@ def test_forward_artifacts_prefers_processed_povs_and_forwards_patches(
assert (dst / "povs" / "triaged").read_text() == "triaged"
assert (dst / "patches" / "fix.diff").read_text() == "patch"
assert records[0]["copied"] == {"povs": 1, "patches": 1}


def test_forward_artifacts_excludes_hidden_and_symlinks(tmp_path: Path) -> None:
compose = _make_run_compose(tmp_path)
target = Target(tmp_path / "work", tmp_path / "proj", None, "new_harness")
run_dir = tmp_path / "old" / "address" / "runs" / "run-1"
exchange = run_dir / "EXCHANGE_DIR" / "target_latest" / "old_harness"
patches_dir = exchange / "patches"
patches_dir.mkdir(parents=True)
(patches_dir / "fix.diff").write_text("visible patch")
(patches_dir / ".hidden").write_text("hidden")
(patches_dir / ".git").mkdir()
(patches_dir / ".git" / "config").write_text("git config")

outside_file = tmp_path / "outside_secret.txt"
outside_file.write_text("secret")
outside_dir = tmp_path / "outside_dir"
outside_dir.mkdir()
(outside_dir / "nested.txt").write_text("nested secret")

link_file = patches_dir / "link.diff"
link_dir = patches_dir / "link_dir"
try:
link_file.symlink_to(outside_file)
link_dir.symlink_to(outside_dir, target_is_directory=True)
except OSError as exc:
pytest.skip(f"Symlink creation unsupported on this platform: {exc}")

assert link_file.is_symlink()
assert link_dir.is_symlink()

source = ForwardArtifactSource(
requested_run_id="run-1",
run_id="run-1",
sanitizer="address",
compose_hash="old",
run_dir=run_dir,
target_key="target_latest",
harness="old_harness",
exchange_dir=exchange,
processed_exchange_dir=None,
)

compose._copy_forward_artifact_sources(
sources=[source],
target=target,
run_id="new-run",
sanitizer="address",
)

dst_patches = (
compose.work_dir.get_exchange_dir(target, "new-run", "address") / "patches"
)
assert (dst_patches / "fix.diff").read_text() == "visible patch"
assert not (dst_patches / ".hidden").exists()
assert not (dst_patches / ".git").exists()
assert not (dst_patches / "link.diff").exists()
assert not (dst_patches / "link_dir").exists()


def test_artifact_input_recursive_copy_excludes_hidden_and_symlinks(
tmp_path: Path, monkeypatch
) -> None:
compose = _make_run_compose(tmp_path)
target = Target(tmp_path / "work", tmp_path / "proj", None, "fuzz_target")
src_dir = tmp_path / "bug_candidates"
src_dir.mkdir()
(src_dir / "candidate.json").write_text('{"id": 1}')
(src_dir / ".hidden").write_text("hidden")
(src_dir / ".hidden_dir").mkdir()
(src_dir / ".hidden_dir" / "secret.txt").write_text("hidden dir")

outside_file = tmp_path / "outside_secret.txt"
outside_file.write_text("secret")
outside_dir = tmp_path / "outside_dir"
outside_dir.mkdir()
(outside_dir / "nested.txt").write_text("nested secret")

link_file = src_dir / "link.json"
link_dir = src_dir / "link_dir"
try:
link_file.symlink_to(outside_file)
link_dir.symlink_to(outside_dir, target_is_directory=True)
except OSError as exc:
pytest.skip(f"Symlink creation unsupported on this platform: {exc}")

assert link_file.is_symlink()
assert link_dir.is_symlink()

captured: dict = {}
_stub_run_for_existing_build(compose, target, monkeypatch, captured)

assert (
compose.run(
target,
run_id="run-1",
build_id="build-1",
sanitizer="address",
artifact_inputs={"bug_candidate": ArtifactInput(directory=src_dir)},
)
is True
)

dst_dir = (
compose.work_dir.get_exchange_dir(target, "run-1", "address") / "bug_candidates"
)
assert (dst_dir / "candidate.json").read_text() == '{"id": 1}'
assert not (dst_dir / ".hidden").exists()
assert not (dst_dir / ".hidden_dir").exists()
assert not (dst_dir / "link.json").exists()
assert not (dst_dir / "link_dir").exists()
Loading