fix: pass max_num_pages and max_file_size to Docling convert (C3)
Defense-in-depth: even if upload validation passes, Docling itself now enforces page count and file size limits. Configurable via MAX_PAGE_COUNT and MAX_FILE_SIZE env vars (0 = unlimited). Ref #57 (C3)
This commit is contained in:
parent
c0fb128718
commit
6327b13614
2 changed files with 9 additions and 2 deletions
|
|
@ -222,7 +222,12 @@ def _convert_sync(file_path: str, options: ConversionOptions) -> ConversionResul
|
|||
)
|
||||
try:
|
||||
conv = _select_converter(options)
|
||||
result = conv.convert(file_path)
|
||||
kwargs: dict = {}
|
||||
if settings.max_page_count > 0:
|
||||
kwargs["max_num_pages"] = settings.max_page_count
|
||||
if settings.max_file_size > 0:
|
||||
kwargs["max_file_size"] = settings.max_file_size
|
||||
result = conv.convert(file_path, **kwargs)
|
||||
finally:
|
||||
_converter_lock.release()
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ class Settings:
|
|||
conversion_timeout: int = 900
|
||||
document_timeout: float = 120.0 # Docling-level per-document timeout (seconds)
|
||||
max_concurrent_analyses: int = 3
|
||||
max_page_count: int = 0 # 0 = unlimited
|
||||
max_page_count: int = 0 # 0 = unlimited (upload validation)
|
||||
max_file_size: int = 0 # 0 = unlimited (Docling-level, bytes)
|
||||
upload_dir: str = "./uploads"
|
||||
db_path: str = "./data/docling_studio.db"
|
||||
cors_origins: list[str] = field(
|
||||
|
|
@ -37,6 +38,7 @@ class Settings:
|
|||
document_timeout=float(os.environ.get("DOCUMENT_TIMEOUT", "120.0")),
|
||||
max_concurrent_analyses=int(os.environ.get("MAX_CONCURRENT_ANALYSES", "3")),
|
||||
max_page_count=int(os.environ.get("MAX_PAGE_COUNT", "0")),
|
||||
max_file_size=int(os.environ.get("MAX_FILE_SIZE", "0")),
|
||||
upload_dir=os.environ.get("UPLOAD_DIR", "./uploads"),
|
||||
db_path=os.environ.get("DB_PATH", "./data/docling_studio.db"),
|
||||
cors_origins=[o.strip() for o in cors_raw.split(",")],
|
||||
|
|
|
|||
Loading…
Reference in a new issue