diff --git a/dev/test_router_coordination.py b/dev/test_router_coordination.py index 163dec2..8914e95 100644 --- a/dev/test_router_coordination.py +++ b/dev/test_router_coordination.py @@ -3,6 +3,7 @@ import json import os import sys import threading +import tempfile import unittest from pathlib import Path from unittest.mock import patch @@ -25,6 +26,14 @@ class CoordinationTests(unittest.TestCase): with self.assertRaisesRegex(RuntimeError, 'rewritten_prompt'): router._parse_prompt_enhancer_result('{"wh_ratio":"1:1"}') + def test_image_data_url_resolves_volume_relative_reference(self): + with tempfile.TemporaryDirectory() as directory, \ + patch.object(router, 'IMAGE_DIR', directory): + path = Path(directory) / '.edit-reference.ref' + path.write_bytes(b'\x89PNG\r\n\x1a\ncontent') + result = router._image_data_url(path.name) + self.assertTrue(result.startswith('data:image/png;base64,')) + def test_mode_uses_one_consistent_controller_snapshot(self): with patch.object(router, 'PROFILE_CONTROL_URL', 'http://controller'), \ patch.object(router, '_profile_controller_request', return_value={ diff --git a/router/ai_profile_router.py b/router/ai_profile_router.py index 61710aa..4ba25a3 100755 --- a/router/ai_profile_router.py +++ b/router/ai_profile_router.py @@ -1410,7 +1410,12 @@ def _restore_qwen(profile: str) -> None: def _image_data_url(path: str) -> str: """Read one already validated local reference image as a data URL.""" - with open(path, "rb") as handle: + image_root = os.path.abspath(IMAGE_DIR) + resolved = (os.path.abspath(path) if os.path.isabs(path) + else os.path.abspath(os.path.join(image_root, path))) + if os.path.commonpath((image_root, resolved)) != image_root: + raise RuntimeError("Referenzbild liegt außerhalb des Bildverzeichnisses") + with open(resolved, "rb") as handle: data = handle.read() if data.startswith(b"\x89PNG\r\n\x1a\n"): mime = "image/png"