Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: media decodes open no protocols, Data Recipe names stay inside their folder (#14463)
Daniel Han5a5aca2ab43f
diff --git a/studio/backend/core/data_recipe/service.py b/studio/backend/core/data_recipe/service.pyindex 0a485300587..42f19840a94 100644--- a/studio/backend/core/data_recipe/service.py+++ b/studio/backend/core/data_recipe/service.py@@ -680,8 +680,26 @@ def _strip_frontend_model_config_metadata(recipe: dict[str, Any]) -> dict[str, A}+def validate_recipe_names(recipe: dict[str, Any]) -> None:+ """Refuse a column, processor or validator target name holding a path separator: the code+ validator writes `<tmp>/<record id>_<column>.py`, and Windows resolves `..` after it lexically."""+ for field in ("columns", "processors"):+ items = recipe.get(field)+ for item in items if isinstance(items, list) else []:+ if not isinstance(item, dict):+ continue+ # A validator's targets can be seed columns, named by the seed file rather than the recipe.+ targets = item.get("target_columns")+ for name in [item.get("name"), *(targets if isinstance(targets, list) else ())]:+ if isinstance(name, str) and ("/" in name or "\\" in name or name in (".", "..")):+ raise ValueError(+ f"Column and processor names can't contain '/' or '\\' or be '.' / '..': {name!r}"+ )++def build_config_builder(recipe: dict[str, Any]):validate_recipe_access(recipe)+ validate_recipe_names(recipe)_apply_data_designer_image_context_patch()from data_designer.config import DataDesignerConfigBuilder # pyright: ignore[reportMissingImports]from data_designer.config.processors import ProcessorType # pyright: ignore[reportMissingImports]diff --git a/studio/backend/core/inference/audio_inputs.py b/studio/backend/core/inference/audio_inputs.pyindex aa078477c49..59395cb5332 100644--- a/studio/backend/core/inference/audio_inputs.py+++ b/studio/backend/core/inference/audio_inputs.py@@ -123,13 +123,25 @@ def _write_json(path: Path, meta: dict[str, Any]) -> None:raise-def _av_open(av, source: str):+def _protocol_options(source) -> dict:+ # A probed concat or HLS playlist opens the files or URLs it names: a path may read+ # files only, a buffer nothing.+ local = isinstance(source, (str, os.PathLike))+ return {"protocol_whitelist": "file" if local else "none"}+++def _av_open(av, source):+ from utils.media_playlist import refuse_playlist++ # `file` stays allowed for a path, so a playlist that names local files is refused here.+ refuse_playlist(source)+ options = _protocol_options(source)try:- return av.open(source, mode = "r", metadata_errors = "ignore")+ return av.open(source, mode = "r", metadata_errors = "ignore", options = options)except TypeError as exc:if "metadata_errors" not in str(exc):raise- return av.open(source, mode = "r", format = None)+ return av.open(source, mode = "r", format = None, options = options)def _decoded_frames(av, container):diff --git a/studio/backend/core/inference/llama_video_input.py b/studio/backend/core/inference/llama_video_input.pyindex b020a273a9e..5b6a5d3e99c 100644--- a/studio/backend/core/inference/llama_video_input.py+++ b/studio/backend/core/inference/llama_video_input.py@@ -60,6 +60,9 @@ def _frame_geometry("format=duration","-of","json",+ # A probed playlist would otherwise open the URLs it names.+ "-protocol_whitelist",+ "file",str(clip),],_PROBE_TIMEOUT_S,@@ -106,6 +109,8 @@ def _packet_duration(ffprobe: str, clip: Path) -> Optional[float]:"packet=pts_time,duration_time","-of","json",+ "-protocol_whitelist",+ "file",str(clip),],_PROBE_TIMEOUT_S,@@ -203,6 +208,10 @@ def shrink_video_for_llama(raw = base64.b64decode(video_b64)except (binascii.Error, ValueError):return video_b64+ from utils.media_playlist import refuse_playlist++ # `-protocol_whitelist file` still lets a playlist read local files: refuse one outright.+ refuse_playlist(raw)try:with tempfile.TemporaryDirectory(prefix = "unsloth-video-") as tmp:source = Path(tmp) / "clip"@@ -225,6 +234,8 @@ def shrink_video_for_llama("-hide_banner","-loglevel","error",+ "-protocol_whitelist",+ "file","-i",str(source),"-map",diff --git a/studio/backend/core/inference/stt_sidecar.py b/studio/backend/core/inference/stt_sidecar.pyindex f87efa24c52..ca8cab6edb2 100644--- a/studio/backend/core/inference/stt_sidecar.py+++ b/studio/backend/core/inference/stt_sidecar.py@@ -1186,16 +1186,20 @@ def _close_engine(engine) -> bool:return not _engine_is_alive(engine)-def _av_open(av, source):+# An upload probed as a concat playlist would otherwise decode the files it names.+NO_PROTOCOLS = {"protocol_whitelist": "none"}+++def _av_open(av, source, **extra):"""Open ``source`` for reading with undecodable metadata ignored. PyAV 19 removed ``metadata_errors`` from ``av.open``, so passing it there raises TypeError before anything is read; retry without it."""try:- return av.open(source, mode = "r", metadata_errors = "ignore")+ return av.open(source, mode = "r", metadata_errors = "ignore", **extra)except TypeError as exc:if "metadata_errors" not in str(exc):raise# format = None is PyAV's own default (probe the container); spelling it keeps this call# distinguishable from Path.open for the text-encoding lint.- return av.open(source, mode = "r", format = None)+ return av.open(source, mode = "r", format = None, **extra)def _decode_audio_bounded(audio: bytes, cancel_event = None):@@ -1241,7 +1245,7 @@ def _decode_audio_bounded(audio: bytes, cancel_event = None):raw_buffer.write(array)try:- with _av_open(av, io.BytesIO(audio)) as container:+ with _av_open(av, io.BytesIO(audio), options = NO_PROTOCOLS) as container:if not container.streams.audio:raise SttAudioDecodeError("Could not decode the audio.")try:diff --git a/studio/backend/core/inference/video_minimax_h3.py b/studio/backend/core/inference/video_minimax_h3.pyindex 2f8c2e30260..ebb8cc9c16d 100644--- a/studio/backend/core/inference/video_minimax_h3.py+++ b/studio/backend/core/inference/video_minimax_h3.py@@ -597,6 +597,12 @@ def h3_reference_frame_size(source_w: int, source_h: int) -> tuple[int, int]:return width, height+def _open_reference_media(av: Any, blob: bytes) -> Any:+ # No protocols: a probed concat or HLS playlist would otherwise open the files it names.+ import io+ return av.open(io.BytesIO(blob), options = {"protocol_whitelist": "none"})++def decode_h3_reference_video(blob: bytes,*,@@ -613,8 +619,6 @@ def decode_h3_reference_video(``(samples, channels)`` at the container's own rate; both engines resample it themselves.``decode_audio=False`` avoids touching an embedded track that a replacement will supersede."""- import io-import avimport numpy as np@@ -645,7 +649,7 @@ def decode_h3_reference_video(waveform, sample_rate = (None, None)if decode_audio:- with av.open(io.BytesIO(blob)) as container:+ with _open_reference_media(av, blob) as container:if container.streams.audio:waveform, sample_rate = _decode_audio_stream(container,@@ -706,9 +710,7 @@ def _fit_h3_video_frame(def _decode_h3_video_without_trim(blob: bytes, av: Any) -> tuple[list, float, Optional[float]]:"""Preserve the existing whole-file rate-based behavior and its 15-second refusal."""- import io-- with av.open(io.BytesIO(blob)) as container:+ with _open_reference_media(av, blob) as container:if not container.streams.video:raise ValueError("That reference file carries no video track.")stream = container.streams.video[0]@@ -745,11 +747,9 @@ def _decode_h3_video_trim_by_timestamp(blob: bytes, av: Any, trim: tuple[float, float]) -> tuple[list, Optional[float]]:"""Select an explicit interval from presentation timestamps and stop at its endpoint."""- import io-start, end = trimtarget_count = int(round((end - start) * H3_FPS))- with av.open(io.BytesIO(blob)) as container:+ with _open_reference_media(av, blob) as container:if not container.streams.video:raise ValueError("That reference file carries no video track.")stream = container.streams.video[0]@@ -819,8 +819,7 @@ def _decode_h3_video_trim_by_ordinal(blob: bytes, av: Any, trim: tuple[float, float]) -> tuple[list, Optional[float]]:"""Fallback for streams whose decoded frames carry no presentation timestamps."""- import io- with av.open(io.BytesIO(blob)) as container:+ with _open_reference_media(av, blob) as container:if not container.streams.video:raise ValueError("That reference file carries no video track.")stream = container.streams.video[0]@@ -869,12 +868,10 @@ def decode_h3_reference_audio(trim_end_seconds: Optional[float] = None,) -> tuple[Any, int]:"""Decode one uploaded audio file to a float32 ``(samples, channels)`` waveform + its rate."""- import io-import avimport numpy as np- with av.open(io.BytesIO(blob)) as container:+ with _open_reference_media(av, blob) as container:if not container.streams.audio:raise ValueError("That reference file carries no audio track.")waveform, sample_rate = _decode_audio_stream(diff --git a/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/config.py b/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/config.pyindex 6b347c4f83d..13a4fa3d338 100644--- a/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/config.py+++ b/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/config.py@@ -45,7 +45,13 @@ class GitHubRepoSeedSource(SeedSource):r = r.strip()if not r:continue- if r.count("/") != 1 or not all(r.split("/")):+ # The name becomes a folder under the scraper's base dir: no backslash or dot-only part.+ if (+ r.count("/") != 1+ or not all(r.split("/"))+ or "\\" in r+ or any(part in (".", "..") for part in r.split("/"))+ ):raise ValueError(f"Each repo must be `owner/name`; got {r!r}")out.append(r)return outdiff --git a/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/scraper_impl/scraper.py b/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/scraper_impl/scraper.pyindex e7695ae3a5c..78a050360f5 100644--- a/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/scraper_impl/scraper.py+++ b/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/scraper_impl/scraper.py@@ -52,6 +52,8 @@ class RepoScraper:# light=True uses trimmed GraphQL queries so PR pages can be larger without hitting GitHub's node-count ceiling.self.light = lightself.repo_dir = base_dir / f"{owner}__{name}"+ if not self.repo_dir.resolve().is_relative_to(base_dir.resolve()):+ raise ValueError(f"Repository {owner}/{name} would be scraped outside {base_dir}")self.repo_dir.mkdir(parents = True, exist_ok = True)self.state = StateStore(base_dir / "state" / f"{owner}__{name}.json")diff --git a/studio/backend/routes/data_recipe/jobs.py b/studio/backend/routes/data_recipe/jobs.pyindex 7518d0c16ab..4335444684e 100644--- a/studio/backend/routes/data_recipe/jobs.py+++ b/studio/backend/routes/data_recipe/jobs.py@@ -52,7 +52,7 @@ from core.data_recipe.huggingface import (publish_recipe_dataset,)from core.data_recipe.jobs import get_job_manager-from core.data_recipe.service import recipe_has_stdio_mcp+from core.data_recipe.service import recipe_has_stdio_mcp, validate_recipe_namesfrom loggers import get_loggerfrom models.data_recipe import (JobCreateResponse,@@ -558,6 +558,10 @@ def create_job(recipe = payload.recipeif not recipe.get("columns"):raise HTTPException(status_code = 400, detail = "Recipe must include columns.")+ try:+ validate_recipe_names(recipe)+ except ValueError as exc:+ raise HTTPException(status_code = 400, detail = str(exc)) from excif recipe_has_stdio_mcp(recipe):require_ui_session_for_local_commands(via_api_key)diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.pyindex 2f7a9e5c7bf..c6b8439d4c3 100644--- a/studio/backend/routes/inference.py+++ b/studio/backend/routes/inference.py@@ -28360,16 +28360,20 @@ def _av_expected_samples(container, sample_rate: int, ceiling: int) -> int:return min(int(seconds * sample_rate) + 1, ceiling)-def _av_open(av, source):+# An upload probed as a concat playlist would otherwise decode the files it names.+NO_PROTOCOLS = {"protocol_whitelist": "none"}+++def _av_open(av, source, **extra):"""Open ``source`` for reading with undecodable metadata ignored. PyAV 19 removed ``metadata_errors`` from ``av.open``, so passing it there raises TypeError before anything is read; retry without it."""try:- return av.open(source, mode = "r", metadata_errors = "ignore")+ return av.open(source, mode = "r", metadata_errors = "ignore", **extra)except TypeError as exc:if "metadata_errors" not in str(exc):raise# format = None is PyAV's own default (probe the container); spelling it keeps this call# distinguishable from Path.open for the text-encoding lint.- return av.open(source, mode = "r", format = None)+ return av.open(source, mode = "r", format = None, **extra)def _decode_audio_mono_with_av(raw: bytes) -> "tuple[np.ndarray, int]":@@ -28411,7 +28415,7 @@ def _decode_audio_mono_with_av(raw: bytes) -> "tuple[np.ndarray, int]":joined = grownjoined[sample_count - len(block) : sample_count] = block- with _av_open(av, io.BytesIO(raw)) as container:+ with _av_open(av, io.BytesIO(raw), options = NO_PROTOCOLS) as container:if not container.streams.audio:raise ValueError("audio container has no audio stream")for frame in container.decode(audio = 0):diff --git a/studio/backend/tests/test_audio_upload_protocols.py b/studio/backend/tests/test_audio_upload_protocols.pynew file mode 100644index 00000000000..844e0005a70--- /dev/null+++ b/studio/backend/tests/test_audio_upload_protocols.py@@ -0,0 +1,35 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Uploaded audio for speech-to-text and chat attachments is decoded from its own bytes only."""++from __future__ import annotations++import pytest++av = pytest.importorskip("av")+np = pytest.importorskip("numpy")++import routes.inference as inference_route+from core.inference import stt_sidecar++from .test_video_minimax_h3_reference_protocols import _playlist, _real_wav_bytes+++def host_wav(tmp_path, monkeypatch):+ (tmp_path / "host.wav").write_bytes(_real_wav_bytes())+ monkeypatch.chdir(tmp_path)+++def test_transcription_upload_playlist_does_not_read_a_host_file(host_wav):+ with pytest.raises(stt_sidecar.SttAudioDecodeError):+ stt_sidecar._decode_audio_bounded(_playlist("host.wav"))+ assert len(stt_sidecar._decode_audio_bounded(_real_wav_bytes())) == 16000+++def test_chat_audio_attachment_playlist_does_not_read_a_host_file(host_wav):+ with pytest.raises(av.error.FFmpegError):+ inference_route._decode_audio_mono_with_av(_playlist("host.wav"))+ samples, rate = inference_route._decode_audio_mono_with_av(_real_wav_bytes())+ assert rate == 8000 and len(samples) == 8000diff --git a/studio/backend/tests/test_media_decode_protocols.py b/studio/backend/tests/test_media_decode_protocols.pynew file mode 100644index 00000000000..35aa1e1ba5f--- /dev/null+++ b/studio/backend/tests/test_media_decode_protocols.py@@ -0,0 +1,183 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Audio decodes and the chat-video shrink never let a probed playlist open what it names."""++from __future__ import annotations++import base64+import io+import json+import sys+from pathlib import Path++import pytest++_BACKEND_ROOT = Path(__file__).resolve().parents[1]+if str(_BACKEND_ROOT) not in sys.path:+ sys.path.insert(0, str(_BACKEND_ROOT))++av = pytest.importorskip("av")+np = pytest.importorskip("numpy")++from core.inference import audio_inputs, llama_video_input # noqa: E402+from utils.datasets import audio_decode # noqa: E402+++def _wav_bytes(seconds: float = 0.5, rate: int = 8000) -> bytes:+ buf = io.BytesIO()+ with av.open(buf, "w", format = "wav") as out:+ stream = out.add_stream("pcm_s16le", rate = rate, layout = "mono")+ frame = av.AudioFrame.from_ndarray(+ np.full((1, int(seconds * rate)), 1000, dtype = np.int16), format = "s16", layout = "mono"+ )+ frame.sample_rate = rate+ for packet in stream.encode(frame):+ out.mux(packet)+ for packet in stream.encode(None):+ out.mux(packet)+ return buf.getvalue()+++def _playlist(name: str) -> bytes:+ # Probed as the concat demuxer, which opens the named file relative to the cwd.+ return f"ffconcat version 1.0\nfile '{name}'\n".encode()+++def host_wav(tmp_path, monkeypatch):+ (tmp_path / "host.wav").write_bytes(_wav_bytes())+ monkeypatch.chdir(tmp_path)+++def test_dataset_audio_buffer_playlist_does_not_read_a_host_file(host_wav):+ with pytest.raises((av.error.FFmpegError, ValueError)):+ audio_decode._decode_with_av(io.BytesIO(_playlist("host.wav")))+ samples, rate = audio_decode._decode_with_av(io.BytesIO(_wav_bytes()))+ assert rate == 8000 and len(samples) == 4000+++def test_speech_encode_buffer_playlist_does_not_read_a_host_file(host_wav):+ with pytest.raises((av.error.FFmpegError, ValueError)):+ audio_inputs.encode_wav(_playlist("host.wav"), "mp3")+ assert audio_inputs.encode_wav(_wav_bytes(), "mp3")[0]+++ "module", [audio_inputs, audio_decode], ids = ["audio_inputs", "audio_decode"]+)+def test_a_saved_playlist_upload_does_not_read_a_host_file(module, host_wav, tmp_path):+ # A path may open `file`, so the playlist itself is refused before FFmpeg probes it.+ upload = tmp_path / "upload.wav"+ upload.write_bytes(_playlist("host.wav"))+ with pytest.raises(ValueError):+ module._av_open(av, str(upload))+++ "module", [audio_inputs, audio_decode], ids = ["audio_inputs", "audio_decode"]+)+def test_a_saved_dash_manifest_upload_is_refused(module, host_wav, tmp_path):+ from utils.media_playlist import PlaylistRefused++ upload = tmp_path / "upload.m4a"+ upload.write_bytes(+ b'<?xml version="1.0"?>\n<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" '+ b'profiles="urn:mpeg:dash:profile:isoff-on-demand:2011"><Period><AdaptationSet>'+ b"<Representation><BaseURL>host.wav</BaseURL></Representation></AdaptationSet></Period></MPD>\n"+ )+ with pytest.raises(PlaylistRefused):+ module._av_open(av, str(upload))+++ "module", [audio_inputs, audio_decode], ids = ["audio_inputs", "audio_decode"]+)+def test_path_sources_may_open_files_only(module, tmp_path, monkeypatch):+ seen = []+ real_open = av.open++ def spy(source, *args, **kwargs):+ seen.append(kwargs.get("options"))+ return real_open(source, *args, **kwargs)++ path = tmp_path / "clip.wav"+ path.write_bytes(_wav_bytes())+ monkeypatch.setattr(av, "open", spy)++ with module._av_open(av, str(path)) as container:+ assert container.streams.audio+ # PyAV 19 refuses metadata_errors and the helper retries, so every attempt is checked.+ assert seen and all(options == {"protocol_whitelist": "file"} for options in seen)+++def test_chat_video_ffmpeg_and_ffprobe_get_a_file_only_whitelist(monkeypatch):+ calls = []++ class _Result:+ def __init__(+ self,+ returncode,+ stdout = b"",+ ):+ self.returncode, self.stdout, self.stderr = returncode, stdout, b""++ def run(argv, _timeout):+ calls.append(list(argv))+ if Path(argv[0]).name == "ffprobe":+ geometry = {+ "streams": [{"width": 4000, "height": 4000, "avg_frame_rate": "10/1"}],+ "format": {"duration": "5.0"},+ }+ return _Result(0, json.dumps(geometry).encode())+ return _Result(1)++ monkeypatch.setattr(llama_video_input.shutil, "which", lambda name: f"/usr/bin/{name}")+ monkeypatch.setattr(llama_video_input, "_run", run)++ clip = base64.b64encode(b"not really a video").decode("ascii")+ assert llama_video_input.shrink_video_for_llama(clip, 1 << 20) == clip++ assert [Path(argv[0]).name for argv in calls] == ["ffprobe", "ffmpeg"]+ for argv in calls:+ i = argv.index("-protocol_whitelist")+ assert argv[i + 1] == "file"+ source = argv.index("-i") + 1 if "-i" in argv else len(argv) - 1+ assert i < source+++ "head",+ [+ b"#EXTM3U\n#EXTINF:1,\n/etc/hostname\n",+ b"\xef\xbb\xbf ffconcat version 1.0\nfile '/etc/hostname'\n",+ # DASH is probed by "<MPD" anywhere in the buffer, after an XML prolog here.+ b'<?xml version="1.0"?>\n<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" '+ b'profiles="urn:mpeg:dash:profile:isoff-on-demand:2011"><Period><AdaptationSet>'+ b"<Representation><BaseURL>host.wav</BaseURL></Representation></AdaptationSet></Period></MPD>\n",+ b"<!--" + b" " * 8192 + b'--><mpd profiles="URN:MPEG:DASH:PROFILE:ISOFF-LIVE:2011"></mpd>',+ ],+)+def test_a_playlist_upload_is_refused_before_ffmpeg_sees_it(tmp_path, head):+ from utils.media_playlist import PlaylistRefused, refuse_playlist++ path = tmp_path / "upload.mp4"+ path.write_bytes(head)+ for source in (str(path), head, io.BytesIO(head)):+ with pytest.raises(PlaylistRefused):+ refuse_playlist(source)+ # Real media headers pass, as does "<MPD" text that FFmpeg would not probe as DASH.+ refuse_playlist(b"\x00\x00\x00\x18ftypmp42")+ refuse_playlist(b"ID3\x04\x00\x00\x00\x00\x00\x10TIT2 <MPD> notes")+ refuse_playlist(b"\x00" + head)+ refuse_playlist(b"RIFF\x00\x00\x00\x00WAVEfmt ")+++def test_shrink_refuses_a_playlist_clip(monkeypatch):+ from core.inference import llama_video_input+ from utils.media_playlist import PlaylistRefused++ clip = base64.b64encode(b"#EXTM3U\n/etc/hostname\n").decode()+ monkeypatch.setattr(llama_video_input.shutil, "which", lambda name: f"/usr/bin/{name}")+ with pytest.raises(PlaylistRefused):+ llama_video_input.shrink_video_for_llama(clip, 1 << 20)diff --git a/studio/backend/tests/test_recipe_names_inside_folder.py b/studio/backend/tests/test_recipe_names_inside_folder.pynew file mode 100644index 00000000000..953bf6bb260--- /dev/null+++ b/studio/backend/tests/test_recipe_names_inside_folder.py@@ -0,0 +1,115 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Recipe strings that become path segments must not hold a path separator: column names become+`<tmp>/<record id>_<column>.py` in the code validator, and GitHub seed repo names become+`<base>/<owner>__<name>` in the scraper."""++import sys+import types+from pathlib import Path++import pytest+from fastapi import HTTPException+from pydantic import BaseModel++from core.data_recipe import service++_BACKEND = Path(__file__).resolve().parents[1]+_PLUGIN_SRC = _BACKEND / "plugins/data-designer-github-repo-seed/src"+_B = chr(92)++_ESCAPING_NAMES = ["x/../../marker", ".." + _B + ".." + _B + "x"]++[email protected]("name", _ESCAPING_NAMES)+def test_a_column_name_that_names_a_path_is_refused(name):+ recipe = {"columns": [{"name": name, "column_type": "expression", "expr": "1"}]}+ # build_config_builder is what validate, preview and the job worker all call.+ with pytest.raises(ValueError):+ service.build_config_builder(recipe)++[email protected]("name", _ESCAPING_NAMES)+def test_a_validator_target_that_names_a_path_is_refused(name):+ # The target can be a seed column whose name comes from the seed file, not from `columns`.+ column = {+ "name": "lint",+ "column_type": "validation",+ "validator_type": "code",+ "validator_params": {"code_lang": "python"},+ "target_columns": ["code", name],+ }+ with pytest.raises(ValueError):+ service.build_config_builder({"columns": [column]})++[email protected]("name", [".", ".."])+def test_a_dot_only_processor_name_is_refused(name):+ # Data Designer writes processor batches under processors-files/<name>/.+ recipe = {"processors": [{"name": name, "processor_type": "schema_transform"}]}+ with pytest.raises(ValueError):+ service.validate_recipe_names(recipe)++[email protected]("name", ["answer", "code_v2", "a.b", "Question 1", "Step 1: answer"])+def test_ordinary_column_names_pass(name):+ service.validate_recipe_names({"columns": [{"name": name}], "processors": [{"name": "drop"}]})+++def test_job_with_an_escaping_column_name_is_refused_before_it_starts(monkeypatch):+ import routes.data_recipe.jobs as jobs_routes+ from models.data_recipe import RecipePayload++ started = []+ monkeypatch.setattr(+ jobs_routes,+ "get_job_manager",+ lambda: type("M", (), {"start": lambda self, **k: started.append(k)})(),+ )+ recipe = {"columns": [{"name": "x/../../marker", "column_type": "expression", "expr": "1"}]}+ with pytest.raises(HTTPException) as exc:+ jobs_routes.create_job(+ RecipePayload(recipe = recipe), request = None, credential = ("u", None), via_api_key = False+ )+ assert exc.value.status_code == 400+ assert started == []+++def plugin_config(monkeypatch):+ # The plugin's base class comes from the recipe engine; a plain pydantic model stands in.+ seed_source = types.ModuleType("data_designer.config.seed_source")+ seed_source.SeedSource = type("SeedSource", (BaseModel,), {})+ for name in ("data_designer", "data_designer.config"):+ monkeypatch.setitem(sys.modules, name, sys.modules.get(name) or types.ModuleType(name))+ monkeypatch.setitem(sys.modules, "data_designer.config.seed_source", seed_source)+ for name in list(sys.modules):+ if name.startswith("data_designer_github_repo_seed"):+ monkeypatch.delitem(sys.modules, name)+ monkeypatch.syspath_prepend(str(_PLUGIN_SRC))+ import importlib.util++ spec = importlib.util.spec_from_file_location(+ "data_designer_github_repo_seed_config_under_test",+ _PLUGIN_SRC / "data_designer_github_repo_seed/config.py",+ )+ module = importlib.util.module_from_spec(spec)+ monkeypatch.setitem(sys.modules, spec.name, module)+ spec.loader.exec_module(module)+ return module+++ "repo", [".." + _B + ".." + _B + "OUTSIDE" + _B + "x/y", "owner/..", "owner/" + _B + "x"]+)+def test_plugin_refuses_a_repo_that_is_not_owner_slash_name(plugin_config, repo):+ with pytest.raises(ValueError):+ plugin_config.GitHubRepoSeedSource(repos = [repo], token = "t")+++def test_plugin_accepts_a_real_repo(plugin_config):+ source = plugin_config.GitHubRepoSeedSource(+ repos = ["unslothai/unsloth", "my-org/my.repo_2"], token = "t"+ )+ assert source.repos == ["unslothai/unsloth", "my-org/my.repo_2"]diff --git a/studio/backend/tests/test_video_minimax_h3_reference_protocols.py b/studio/backend/tests/test_video_minimax_h3_reference_protocols.pynew file mode 100644index 00000000000..bb8a43c9c85--- /dev/null+++ b/studio/backend/tests/test_video_minimax_h3_reference_protocols.py@@ -0,0 +1,85 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""MiniMax-H3 reference uploads are decoded from their own bytes, never from files they name."""++from __future__ import annotations++import io++import pytest++from core.inference import video_minimax_h3 as h3++from .test_video_gallery import _real_mp4_bytes, _real_mp4_with_audio++av = pytest.importorskip("av")+np = pytest.importorskip("numpy")+++def _real_wav_bytes(seconds: float = 1.0, rate: int = 8000) -> bytes:+ buf = io.BytesIO()+ with av.open(buf, "w", format = "wav") as out:+ stream = out.add_stream("pcm_s16le", rate = rate, layout = "mono")+ frame = av.AudioFrame.from_ndarray(+ np.full((1, int(seconds * rate)), 1000, dtype = np.int16), format = "s16", layout = "mono"+ )+ frame.sample_rate = rate+ for packet in stream.encode(frame):+ out.mux(packet)+ for packet in stream.encode(None):+ out.mux(packet)+ return buf.getvalue()+++def _playlist(name: str) -> bytes:+ # FFmpeg probes this as the concat demuxer, which opens the named file relative to the cwd.+ return f"ffconcat version 1.0\nfile '{name}'\n".encode()+++def host_files(tmp_path, monkeypatch):+ (tmp_path / "host.wav").write_bytes(_real_wav_bytes())+ (tmp_path / "host.mp4").write_bytes(_real_mp4_bytes(frames = 24))+ monkeypatch.chdir(tmp_path)+ return tmp_path+++def test_reference_audio_playlist_does_not_read_a_host_file(host_files):+ with pytest.raises(av.error.FFmpegError):+ h3.decode_h3_reference_audio(_playlist("host.wav"))++[email protected]("trim", [(None, None), (0.0, 2.5)])+def test_reference_video_playlist_does_not_read_a_host_file(host_files, trim):+ with pytest.raises(av.error.FFmpegError):+ h3.decode_h3_reference_video(+ _playlist("host.mp4"), trim_start_seconds = trim[0], trim_end_seconds = trim[1]+ )+++def test_reference_video_ordinal_fallback_does_not_read_a_host_file(host_files):+ with pytest.raises(av.error.FFmpegError):+ h3._decode_h3_video_trim_by_ordinal(_playlist("host.mp4"), av, (0.0, 2.5))+++def test_every_reference_open_allows_no_protocols(monkeypatch):+ seen = []+ real_open = av.open++ def recording_open(*args, **kwargs):+ seen.append(kwargs.get("options"))+ return real_open(*args, **kwargs)++ clip, wav = _real_mp4_with_audio(seconds = 3), _real_wav_bytes()+ monkeypatch.setattr(av, "open", recording_open)++ frames, waveform, _ = h3.decode_h3_reference_video(clip)+ assert frames and waveform is not None+ frames, _, _ = h3.decode_h3_reference_video(clip, trim_start_seconds = 0.0, trim_end_seconds = 2.5)+ assert frames+ assert h3._decode_h3_video_trim_by_ordinal(clip, av, (0.0, 2.5))[0]+ waveform, rate = h3.decode_h3_reference_audio(wav)+ assert rate == 8000 and len(waveform) == 8000++ assert seen and all(opts == {"protocol_whitelist": "none"} for opts in seen), seendiff --git a/studio/backend/utils/datasets/audio_decode.py b/studio/backend/utils/datasets/audio_decode.pyindex 458c427490b..5d78dcc02cd 100644--- a/studio/backend/utils/datasets/audio_decode.py+++ b/studio/backend/utils/datasets/audio_decode.py@@ -5,6 +5,7 @@from __future__ import annotations+import osimport threadingfrom typing import Any, Optional@@ -46,14 +47,21 @@ def _token_for_url(path: str, token_per_repo_id: Optional[dict]) -> Any:def _av_open(av, source):"""Open ``source`` for reading with undecodable metadata ignored. PyAV 19 removed ``metadata_errors`` from ``av.open``, so passing it there raises TypeError before anything is read; retry without it."""+ # A probed concat or HLS playlist opens what it names: a path may read files only, a buffer nothing.+ from utils.media_playlist import refuse_playlist++ # `file` stays allowed for a path, so a playlist that names local files is refused here.+ refuse_playlist(source)+ local = isinstance(source, (str, os.PathLike))+ options = {"protocol_whitelist": "file" if local else "none"}try:- return av.open(source, mode = "r", metadata_errors = "ignore")+ return av.open(source, mode = "r", metadata_errors = "ignore", options = options)except TypeError as exc:if "metadata_errors" not in str(exc):raise# format = None is PyAV's own default (probe the container); spelling it keeps this call# distinguishable from Path.open for the text-encoding lint.- return av.open(source, mode = "r", format = None)+ return av.open(source, mode = "r", format = None, options = options)def _decode_with_av(source: Any, stream_index: Optional[int] = None) -> "tuple[Any, int]":diff --git a/studio/backend/utils/media_playlist.py b/studio/backend/utils/media_playlist.pynew file mode 100644index 00000000000..5719bfdc1a8--- /dev/null+++ b/studio/backend/utils/media_playlist.py@@ -0,0 +1,46 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Refuse uploads that FFmpeg would probe as a playlist (HLS, concat, DASH), which open the files they name."""++from __future__ import annotations++import io+import os+from typing import Any++_HEAD_BYTES = 1 << 20 # FFmpeg grows its probe buffer past a few KB+_PLAYLIST_MARKS = (b"#EXTM3U", b"ffconcat")+++class PlaylistRefused(ValueError):+ """The media is a playlist that would read other files on the server."""+++def _head(source: Any) -> bytes:+ if isinstance(source, (bytes, bytearray, memoryview)):+ return bytes(source[:_HEAD_BYTES])+ if isinstance(source, (str, os.PathLike)):+ try:+ with open(source, "rb") as handle:+ return handle.read(_HEAD_BYTES)+ except OSError:+ return b""+ if isinstance(source, io.IOBase) and source.seekable():+ at = source.tell()+ try:+ return source.read(_HEAD_BYTES) or b""+ finally:+ source.seek(at)+ return b""+++def refuse_playlist(source: Any) -> None:+ """Raise ``PlaylistRefused`` when ``source`` looks like an HLS, concat or DASH playlist."""+ raw = _head(source)+ head = raw.lstrip(b"\xef\xbb\xbf \t\r\n")+ # Mirrors FFmpeg's dash_probe: case-insensitive "<MPD" plus a DASH profile, up to the first NUL.+ text = raw.split(b"\x00", 1)[0].lower()+ dash = b"<mpd" in text and (b"dash:profile" in text or b"3gpp:pss:profile:dash1" in text)+ if head.startswith(_PLAYLIST_MARKS) or dash:+ raise PlaylistRefused("Playlists are not accepted as media uploads.")