mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 02:41:06 -05:00
Sandbox Process Creation
This commit is contained in:
@@ -5,6 +5,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, Any, Optional
|
from typing import Dict, Any, Optional
|
||||||
|
from security import safe_command
|
||||||
|
|
||||||
# Configure logging
|
# Configure logging
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
@@ -166,8 +167,7 @@ class FFmpeg:
|
|||||||
"""Get FFmpeg version"""
|
"""Get FFmpeg version"""
|
||||||
try:
|
try:
|
||||||
import subprocess
|
import subprocess
|
||||||
result = subprocess.run(
|
result = safe_command.run(subprocess.run, [str(self.ffmpeg_path), "-version"],
|
||||||
[str(self.ffmpeg_path), "-version"],
|
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
timeout=5
|
timeout=5
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import lzma
|
|||||||
# try:
|
# try:
|
||||||
# Try relative imports first
|
# Try relative imports first
|
||||||
from exceptions import DownloadError
|
from exceptions import DownloadError
|
||||||
|
from security import safe_command
|
||||||
|
|
||||||
# except ImportError:
|
# except ImportError:
|
||||||
# Fall back to absolute imports if relative imports fail
|
# Fall back to absolute imports if relative imports fail
|
||||||
@@ -352,8 +353,7 @@ class FFmpegDownloader:
|
|||||||
|
|
||||||
# Test FFmpeg functionality with enhanced error handling
|
# Test FFmpeg functionality with enhanced error handling
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(
|
result = safe_command.run(subprocess.run, [str(self.ffmpeg_path), "-version"],
|
||||||
[str(self.ffmpeg_path), "-version"],
|
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
timeout=5,
|
timeout=5,
|
||||||
@@ -370,8 +370,7 @@ class FFmpegDownloader:
|
|||||||
|
|
||||||
# Test FFprobe functionality with enhanced error handling
|
# Test FFprobe functionality with enhanced error handling
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(
|
result = safe_command.run(subprocess.run, [str(self.ffprobe_path), "-version"],
|
||||||
[str(self.ffprobe_path), "-version"],
|
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
timeout=5,
|
timeout=5,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import platform
|
|||||||
import re
|
import re
|
||||||
from typing import Dict, List, Tuple
|
from typing import Dict, List, Tuple
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from security import safe_command
|
||||||
|
|
||||||
logger = logging.getLogger("VideoArchiver")
|
logger = logging.getLogger("VideoArchiver")
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ class GPUDetector:
|
|||||||
try:
|
try:
|
||||||
# Use PowerShell to get GPU info
|
# Use PowerShell to get GPU info
|
||||||
cmd = ["powershell", "-Command", "Get-WmiObject Win32_VideoController | Select-Object Name"]
|
cmd = ["powershell", "-Command", "Get-WmiObject Win32_VideoController | Select-Object Name"]
|
||||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
|
result = safe_command.run(subprocess.run, cmd, capture_output=True, text=True, timeout=10)
|
||||||
|
|
||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
output = result.stdout.lower()
|
output = result.stdout.lower()
|
||||||
@@ -153,7 +154,7 @@ class GPUDetector:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
cmd = ["system_profiler", "SPDisplaysDataType"]
|
cmd = ["system_profiler", "SPDisplaysDataType"]
|
||||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
|
result = safe_command.run(subprocess.run, cmd, capture_output=True, text=True, timeout=10)
|
||||||
|
|
||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
output = result.stdout.lower()
|
output = result.stdout.lower()
|
||||||
@@ -173,7 +174,7 @@ class GPUDetector:
|
|||||||
try:
|
try:
|
||||||
# Check FFmpeg encoders
|
# Check FFmpeg encoders
|
||||||
cmd = [str(self.ffmpeg_path), "-hide_banner", "-encoders"]
|
cmd = [str(self.ffmpeg_path), "-hide_banner", "-encoders"]
|
||||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
|
result = safe_command.run(subprocess.run, cmd, capture_output=True, text=True, timeout=10)
|
||||||
|
|
||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
output = result.stdout.lower()
|
output = result.stdout.lower()
|
||||||
@@ -250,7 +251,7 @@ class GPUDetector:
|
|||||||
|
|
||||||
elif system == "windows":
|
elif system == "windows":
|
||||||
cmd = ["powershell", "-Command", "Get-WmiObject Win32_VideoController | Select-Object Name"]
|
cmd = ["powershell", "-Command", "Get-WmiObject Win32_VideoController | Select-Object Name"]
|
||||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
|
result = safe_command.run(subprocess.run, cmd, capture_output=True, text=True, timeout=10)
|
||||||
|
|
||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
for line in result.stdout.splitlines():
|
for line in result.stdout.splitlines():
|
||||||
@@ -265,7 +266,7 @@ class GPUDetector:
|
|||||||
|
|
||||||
elif system == "darwin":
|
elif system == "darwin":
|
||||||
cmd = ["system_profiler", "SPDisplaysDataType"]
|
cmd = ["system_profiler", "SPDisplaysDataType"]
|
||||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
|
result = safe_command.run(subprocess.run, cmd, capture_output=True, text=True, timeout=10)
|
||||||
|
|
||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
current_gpu = None
|
current_gpu = None
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import psutil # type: ignore
|
|||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
from typing import Set, Optional
|
from typing import Set, Optional
|
||||||
|
from security import safe_command
|
||||||
|
|
||||||
logger = logging.getLogger("FFmpegProcessManager")
|
logger = logging.getLogger("FFmpegProcessManager")
|
||||||
|
|
||||||
@@ -90,8 +91,7 @@ class ProcessManager:
|
|||||||
"""
|
"""
|
||||||
process = None
|
process = None
|
||||||
try:
|
try:
|
||||||
process = subprocess.Popen(
|
process = safe_command.run(subprocess.Popen, command,
|
||||||
command,
|
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
text=True
|
text=True
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from contextlib import contextmanager
|
|||||||
import tempfile
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
import json
|
import json
|
||||||
|
from security import safe_command
|
||||||
|
|
||||||
logger = logging.getLogger("VideoArchiver")
|
logger = logging.getLogger("VideoArchiver")
|
||||||
|
|
||||||
@@ -126,8 +127,7 @@ class VideoAnalyzer:
|
|||||||
]
|
]
|
||||||
|
|
||||||
logger.debug(f"Running ffprobe command: {' '.join(cmd)}")
|
logger.debug(f"Running ffprobe command: {' '.join(cmd)}")
|
||||||
result = subprocess.run(
|
result = safe_command.run(subprocess.run, cmd,
|
||||||
cmd,
|
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
text=True,
|
text=True,
|
||||||
@@ -193,8 +193,7 @@ class VideoAnalyzer:
|
|||||||
]
|
]
|
||||||
|
|
||||||
logger.debug(f"Running dark scene analysis: {' '.join(sample_cmd)}")
|
logger.debug(f"Running dark scene analysis: {' '.join(sample_cmd)}")
|
||||||
result = subprocess.run(
|
result = safe_command.run(subprocess.run, sample_cmd,
|
||||||
sample_cmd,
|
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
timeout=60 # Add timeout
|
timeout=60 # Add timeout
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
from utils.exceptions import VideoVerificationError
|
from utils.exceptions import VideoVerificationError
|
||||||
from utils.file_deletion import SecureFileDeleter
|
from utils.file_deletion import SecureFileDeleter
|
||||||
|
from security import safe_command
|
||||||
|
|
||||||
logger = logging.getLogger("VideoArchiver")
|
logger = logging.getLogger("VideoArchiver")
|
||||||
|
|
||||||
@@ -64,8 +65,7 @@ class FileOperations:
|
|||||||
file_path,
|
file_path,
|
||||||
]
|
]
|
||||||
|
|
||||||
result = subprocess.run(
|
result = safe_command.run(subprocess.run, cmd,
|
||||||
cmd,
|
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
text=True,
|
text=True,
|
||||||
@@ -120,7 +120,7 @@ class FileOperations:
|
|||||||
"-show_format",
|
"-show_format",
|
||||||
file_path,
|
file_path,
|
||||||
]
|
]
|
||||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
result = safe_command.run(subprocess.run, cmd, capture_output=True, text=True)
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
raise Exception(f"FFprobe failed: {result.stderr}")
|
raise Exception(f"FFprobe failed: {result.stderr}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user