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
2 changes: 1 addition & 1 deletion framework/py/flwr/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _verify_hashes(list_content: str, tmpdir: Path) -> bool:
True if all file hashes match, False otherwise.
"""
for line in list_content.strip().split("\n"):
rel_path, hash_expected, _ = line.split(",")
rel_path, hash_expected, _ = line.rsplit(",", maxsplit=2)
file_path = tmpdir / rel_path
if not file_path.exists() or get_sha256_hash(file_path) != hash_expected:
return False
Expand Down
14 changes: 13 additions & 1 deletion framework/py/flwr/cli/install_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""Tests for Flower command line interface `install` command."""


import hashlib
import io
import zipfile
from pathlib import Path
Expand All @@ -23,7 +24,7 @@
import pytest

from .archive_utils import safe_extract_zip
from .install import install_from_fab
from .install import _verify_hashes, install_from_fab


def _zip_bytes(entries: list[tuple[str, bytes]]) -> bytes:
Expand Down Expand Up @@ -65,6 +66,17 @@ def test_safe_extract_zip_rejects_absolute_paths(tmp_path: Path) -> None:
safe_extract_zip(zf, tmp_path)


def test_verify_hashes_accepts_comma_in_file_name(tmp_path: Path) -> None:
"""Hash verification should preserve commas in manifest file paths."""
file_name = "metrics,round=1.json"
file_content = b"{}"
(tmp_path / file_name).write_bytes(file_content)
file_hash = hashlib.sha256(file_content).hexdigest()
content_manifest = f"{file_name},{file_hash},{len(file_content) * 8}"

assert _verify_hashes(content_manifest, tmp_path)


def test_install_from_fab_rejects_zip_slip(tmp_path: Path) -> None:
"""install_from_fab should fail fast on zip-slip entries."""
fab_bytes = _zip_bytes(
Expand Down