INNER CODE UNIT · Python

get_safe_image_path

virajmavani/semi-auto-image-annotation-tool · web/backend/main.py:121

def get_safe_image_path(filename: str) -> Path:
    """Get validated image path from dataset directory"""
    if current_dataset_dir is None:
        raise HTTPException(status_code=400, detail="No dataset directory set")

    validate_filename(filename)
    full_path = (current_dataset_dir / filename).resolve()

    # Ensure resolved path is still within dataset directory
    if not str(full_path).startswith(str(current_dataset_dir.resolve())):
        raise HTTPException(status_code=400, detail="Invalid path")

    if not full_path.exists():
        raise HTTPException(status_code=404, detail="Image not found")

    return full_path

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…