{"record":{"id":"365c09a15d901870","repo":"affaan-m/ECC","slug":"download-exceeds-maximum-allowed-size-365c09","errorCode":null,"errorMessage":"download exceeds maximum allowed size","messagePattern":"download exceeds maximum allowed size","errorType":"exception","errorClass":"FalError","httpStatus":null,"severity":"error","filePath":"skills/taste-distillation/scripts/taste/falapi.py","lineNumber":712,"sourceCode":"    opener = urllib.request.build_opener(_SafeRedirect())\n    temporary = None\n    try:\n        with opener.open(req, timeout=300) as resp:\n            declared = getattr(resp, \"headers\", {}).get(\"Content-Length\")\n            expected = int(declared) if declared is not None else None\n            if expected is not None and not 0 <= expected <= MAX_DOWNLOAD_BYTES:\n                raise FalError(\"download declares an invalid or excessive size\")\n            with tempfile.NamedTemporaryFile(dir=dest.parent, prefix=\".taste-download-\",\n                                             delete=False) as fh:\n                temporary = Path(fh.name)\n                total = 0\n                while True:\n                    chunk = resp.read(min(1024 * 1024, MAX_DOWNLOAD_BYTES - total + 1))\n                    if not chunk:\n                        break\n                    total += len(chunk)\n                    if total > MAX_DOWNLOAD_BYTES:\n                        raise FalError(\"download exceeds maximum allowed size\")\n                    fh.write(chunk)\n                if expected is not None and total != expected:\n                    raise FalError(\"download length does not match declared size\")\n        os.replace(temporary, dest)\n        temporary = None\n    except FalError:\n        raise\n    except Exception:\n        raise FalError(\"download failed; existing destination preserved\") from None\n    finally:\n        if temporary is not None:\n            temporary.unlink(missing_ok=True)\n    return dest\n\n\n# ---------------------------------------------------------------------------\n# dry-run stubs\n# ---------------------------------------------------------------------------","sourceCodeStart":694,"sourceCodeEnd":730,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/skills/taste-distillation/scripts/taste/falapi.py#L694-L730","documentation":"While streaming the response body, download() accumulates bytes and aborts as soon as total exceeds MAX_DOWNLOAD_BYTES. This catches cases the Content-Length check cannot: chunked transfer-encoding with no declared length, or a server that sends more than it declared.","triggerScenarios":"Downloading a response that streams more than MAX_DOWNLOAD_BYTES bytes, either via chunked encoding (no Content-Length) or by lying about its declared length.","commonSituations":"A generation returned an unexpectedly enormous video; a redirect to a large file; a malicious or broken server streaming unbounded data; misjudging MAX_DOWNLOAD_BYTES for long clips.","solutions":["Check the actual size of the asset (e.g. via a HEAD request) before downloading","Increase MAX_DOWNLOAD_BYTES if the workload legitimately needs larger files","Use a smaller/max-duration generation option in the fal API call so outputs stay under the limit","Free disk/write to a stream instead if you need unbounded downloads (requires code change)"],"exampleFix":"// before\nMAX_DOWNLOAD_BYTES = 50 * 1024 * 1024  # too small for 4K video\n// after\nMAX_DOWNLOAD_BYTES = 512 * 1024 * 1024","handlingStrategy":"validation","validationCode":"size = int(urllib.request.urlopen(urllib.request.Request(url, method=\"HEAD\")).headers[\"Content-Length\"])\nif size > MAX_DOWNLOAD_BYTES:\n    raise ValueError(\"asset too large to download\")","typeGuard":null,"tryCatchPattern":"try:\n    download(url, dest)\nexcept FalError as e:\n    if \"exceeds maximum\" in str(e):\n        request_smaller_asset(url)  # or raise MAX_DOWNLOAD_BYTES deliberately","preventionTips":["HEAD-request size before download","Constrain generation parameters (resolution/duration) so outputs stay under the limit","Monitor MAX_DOWNLOAD_BYTES against real asset sizes"],"tags":["network","http","size-limit"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}