affaan-m/ECC · error · FalError

download exceeds maximum allowed size

Error message

download exceeds maximum allowed size

What it means

While streaming the response body, download() tracks the total bytes read and aborts with FalError if it exceeds MAX_DOWNLOAD_BYTES. This guards against servers that lie about (or omit) Content-Length and keep sending data, so the temp file cannot grow unbounded.

Solutions

  1. Increase MAX_DOWNLOAD_BYTES if the asset legitimately needs more space
  2. Verify the asset's true size beforehand with a HEAD request
  3. Download with your own client if you need different streaming limits
  4. Retry against a direct fal.media URL, bypassing any proxy that might mangle the stream

Example fix

// before
while True:
    chunk = resp.read(1024 * 1024)
// after
# raise MAX_DOWNLOAD_BYTES in falapi.py first, or pre-check:
head = requests.head(url); size = int(head.headers.get('Content-Length', 0))
assert 0 < size <= MAX_DOWNLOAD_BYTES
Defensive patterns

Strategy: validation

Validate before calling

size = int(urllib.request.urlopen(urllib.request.Request(url, method='HEAD')).headers.get('Content-Length', 0))
assert size <= MAX_DOWNLOAD_BYTES

Prevention

When it happens

Trigger: A server omits Content-Length (so the declared-size check is skipped) and streams more than MAX_DOWNLOAD_BYTES; a server sends fewer bytes in the header than it actually writes; a redirect or proxy duplicates/loops the body stream.

Common situations: Chunked-transfer responses without a declared length; downloading a bundle bigger than the limit where the header check never fired; malicious or misconfigured endpoint streaming endlessly.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/b40dee541f891d35. Report an issue: GitHub.

Appendix: source

Thrown at skills/taste-application/scripts/taste/falapi.py:712

    opener = urllib.request.build_opener(_SafeRedirect())
    temporary = None
    try:
        with opener.open(req, timeout=300) as resp:
            declared = getattr(resp, "headers", {}).get("Content-Length")
            expected = int(declared) if declared is not None else None
            if expected is not None and not 0 <= expected <= MAX_DOWNLOAD_BYTES:
                raise FalError("download declares an invalid or excessive size")
            with tempfile.NamedTemporaryFile(dir=dest.parent, prefix=".taste-download-",
                                             delete=False) as fh:
                temporary = Path(fh.name)
                total = 0
                while True:
                    chunk = resp.read(min(1024 * 1024, MAX_DOWNLOAD_BYTES - total + 1))
                    if not chunk:
                        break
                    total += len(chunk)
                    if total > MAX_DOWNLOAD_BYTES:
                        raise FalError("download exceeds maximum allowed size")
                    fh.write(chunk)
                if expected is not None and total != expected:
                    raise FalError("download length does not match declared size")
        os.replace(temporary, dest)
        temporary = None
    except FalError:
        raise
    except Exception:
        raise FalError("download failed; existing destination preserved") from None
    finally:
        if temporary is not None:
            temporary.unlink(missing_ok=True)
    return dest


# ---------------------------------------------------------------------------
# dry-run stubs
# ---------------------------------------------------------------------------

View on GitHub (pinned to 8321021c54)