{"record":{"id":"e65ebd9e983ef1f0","repo":"HKUDS/DeepTutor","slug":"archive-sanitized-filename-exceeds-maximum-siz","errorCode":null,"errorMessage":"Archive '{sanitized_filename}' exceeds maximum size limit of {format_bytes_human_readable(max_size)}","messagePattern":"Archive '(.+?)' exceeds maximum size limit of (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"deeptutor/api/routers/knowledge.py","lineNumber":271,"sourceCode":"    extracted via :func:`safe_extract_zip` (Zip Slip / zip-bomb / extension\n    guards). Returns the list of written file paths.\n    \"\"\"\n    import tempfile\n    import zipfile\n\n    from deeptutor.utils.archive_extractor import ArchiveTooLargeError, safe_extract_zip\n\n    file.file.seek(0)\n    max_size = DocumentValidator.MAX_FILE_SIZE\n    tmp_path: Path | None = None\n    try:\n        with tempfile.NamedTemporaryFile(suffix=\".zip\", delete=False) as tmp:\n            tmp_path = Path(tmp.name)\n            written = 0\n            for chunk in iter(lambda: file.file.read(8192), b\"\"):\n                written += len(chunk)\n                if written > max_size:\n                    raise HTTPException(\n                        status_code=400,\n                        detail=(\n                            f\"Archive '{sanitized_filename}' exceeds maximum size limit of \"\n                            f\"{format_bytes_human_readable(max_size)}\"\n                        ),\n                    )\n                tmp.write(chunk)\n\n        try:\n            result = safe_extract_zip(\n                tmp_path, target_dir, allowed_extensions=allowed_extensions or set()\n            )\n        except ArchiveTooLargeError as exc:\n            raise HTTPException(\n                status_code=400,\n                detail=f\"Rejected archive '{sanitized_filename}': {exc}\",\n            ) from exc\n        except zipfile.BadZipFile as exc:","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/api/routers/knowledge.py#L253-L289","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import os\nif os.path.getsize(zip_path) > MAX_ARCHIVE_BYTES:\n    raise ValueError('zip too large — split or trim before upload')","typeGuard":null,"tryCatchPattern":"resp = upload(zip_path)\nif resp.status_code == 400 and 'exceeds maximum size' in resp.text:\n    trim_or_split_archive(zip_path)","preventionTips":["Check the configured archive size cap before uploading","Prefer multiple smaller archives for large corpora"],"tags":["knowledge-base","upload","zip","size-limit","http-400"],"backgroundTag":"upload-size-limit-exceeded","analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}