HKUDS/DeepTutor · warning · HTTPException
Archive '{sanitized_filename}' exceeds maximum size limit of
Error message
Archive '{sanitized_filename}' exceeds maximum size limit of {format_bytes_human_readable(max_size)} What it means
400 raised inside _save_zip_archive while streaming an uploaded zip to a temp file: once cumulative bytes exceed max_size, the upload is aborted mid-stream. This bounds memory/disk abuse from archive uploads to the knowledge base.
Source
Thrown at deeptutor/api/routers/knowledge.py:271
extracted via :func:`safe_extract_zip` (Zip Slip / zip-bomb / extension
guards). Returns the list of written file paths.
"""
import tempfile
import zipfile
from deeptutor.utils.archive_extractor import ArchiveTooLargeError, safe_extract_zip
file.file.seek(0)
max_size = DocumentValidator.MAX_FILE_SIZE
tmp_path: Path | None = None
try:
with tempfile.NamedTemporaryFile(suffix=".zip", delete=False) as tmp:
tmp_path = Path(tmp.name)
written = 0
for chunk in iter(lambda: file.file.read(8192), b""):
written += len(chunk)
if written > max_size:
raise HTTPException(
status_code=400,
detail=(
f"Archive '{sanitized_filename}' exceeds maximum size limit of "
f"{format_bytes_human_readable(max_size)}"
),
)
tmp.write(chunk)
try:
result = safe_extract_zip(
tmp_path, target_dir, allowed_extensions=allowed_extensions or set()
)
except ArchiveTooLargeError as exc:
raise HTTPException(
status_code=400,
detail=f"Rejected archive '{sanitized_filename}': {exc}",
) from exc
except zipfile.BadZipFile as exc:View on GitHub (pinned to 3e82f13042)
Solutions
- Check the limit named in the message (human-readable) and compress or trim the archive below it
- Split the material into multiple archives or upload files individually
- Raise the archive size limit in server config if the use case demands it
Defensive patterns
Strategy: validation
Validate before calling
import os
if os.path.getsize(zip_path) > MAX_ARCHIVE_BYTES:
raise ValueError('zip too large — split or trim before upload') Try / catch
resp = upload(zip_path)
if resp.status_code == 400 and 'exceeds maximum size' in resp.text:
trim_or_split_archive(zip_path) Prevention
- Check the configured archive size cap before uploading
- Prefer multiple smaller archives for large corpora
When it happens
Trigger: POST upload of a .zip whose total size exceeds the configured max archive size; the check fires during chunked read, so it triggers even before extraction.
Common situations: Users zipping entire course materials into one archive; max size lowered by config; forgetting the limit exists because single-file uploads have a different cap.
Related errors
- Rejected archive '{sanitized_filename}': {exc}
- '{sanitized_filename}' is not a valid zip archive.
- Archive '{sanitized_filename}' contained no supported files.
- File '{sanitized_filename}' exceeds maximum size limit of {s
- Validation failed for file '{original_filename}': {format_ex
AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27).
Data as JSON: /api/errors/e65ebd9e983ef1f0.
Report an issue: GitHub.