From dc3deda8d2a29f97f7eee4e5a8c05b6d87805f6e Mon Sep 17 00:00:00 2001 From: CI Bot Date: Thu, 20 Aug 2026 11:28:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20AI=20Code=20Review?= =?UTF-8?q?=20=E7=9A=84=E5=AE=89=E5=85=A8=E5=92=8C=E7=A8=B3=E5=AE=9A?= =?UTF-8?q?=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. tempfile.mktemp -> NamedTemporaryFile(delete=False) - 避免 TOCTOU 竞态条件安全风险 2. subprocess.run capture_output=True -> stdout=DEVNULL, stderr=PIPE - 避免 FFmpeg 大量日志输出导致内存溢出 OOM --- apps/worker/worker_app/tasks/ingest.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/worker/worker_app/tasks/ingest.py b/apps/worker/worker_app/tasks/ingest.py index 1305e9846..072d97d7a 100755 --- a/apps/worker/worker_app/tasks/ingest.py +++ b/apps/worker/worker_app/tasks/ingest.py @@ -247,7 +247,9 @@ def ingest_asset(job_id: str) -> dict: ) _tc_tmp = None try: - _tc_tmp = Path(tempfile.mktemp(suffix="_h264.mp4")) + _tc_tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix="_h264.mp4") + _tc_tmp = Path(_tc_tmp_file.name) + _tc_tmp_file.close() # 关闭文件描述符,ffmpeg 会自己打开 _cmd = [ "ffmpeg", "-y", @@ -273,7 +275,8 @@ def ingest_asset(job_id: str) -> dict: ] _proc = subprocess.run( _cmd, - capture_output=True, + stdout=subprocess.DEVNULL, + stderr=subprocess.PIPE, text=True, timeout=300, )