{"record":{"id":"1def2086edc97c10","repo":"666ghj/MiroFish","slug":"github-api-response-exceeded-the-size-limit","errorCode":null,"errorMessage":"GitHub API response exceeded the size limit","messagePattern":"GitHub API response exceeded the size limit","errorType":"exception","errorClass":"FetchError","httpStatus":null,"severity":"error","filePath":"scripts/fetch_star_count.py","lineNumber":64,"sourceCode":"        return FetchError(\"GitHub API request was denied\")\n    if status == 404:\n        return FetchError(\"repository metadata was not found\")\n    if status == 429:\n        return FetchError(\"GitHub API rate limit was exhausted\")\n    if 500 <= status <= 599:\n        return FetchError(\"GitHub API is unavailable\")\n    return FetchError(\"GitHub API request failed\")\n\n\ndef _read_response(response: Any) -> bytes:\n    raw_length = response.headers.get(\"Content-Length\")\n    if raw_length is not None:\n        try:\n            content_length = int(raw_length, 10)\n        except (TypeError, ValueError) as exc:\n            raise FetchError(\"GitHub API returned invalid response metadata\") from exc\n        if content_length < 0 or content_length > MAX_HTTP_BYTES:\n            raise FetchError(\"GitHub API response exceeded the size limit\")\n\n    payload = response.read(MAX_HTTP_BYTES + 1)\n    if len(payload) > MAX_HTTP_BYTES:\n        raise FetchError(\"GitHub API response exceeded the size limit\")\n    return payload\n\n\ndef fetch_star_count(token: str, opener: Any | None = None) -> int:\n    if not token or len(token) > 4_096 or \"\\r\" in token or \"\\n\" in token:\n        raise FetchError(\"GITHUB_TOKEN is missing or invalid\")\n\n    request = urllib.request.Request(\n        API_URL,\n        headers={\n            \"Accept\": \"application/vnd.github+json\",\n            \"Authorization\": f\"Bearer {token}\",\n            \"User-Agent\": \"Repository-Star-History-Fetcher\",\n            \"X-GitHub-Api-Version\": API_VERSION,","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/666ghj/MiroFish/blob/b5b53acc57189a4a42e44a23e149dc655c98fe82/scripts/fetch_star_count.py#L46-L82","documentation":"Raised by _read_response when the declared Content-Length is negative or exceeds MAX_HTTP_BYTES (1,000,000). The script deliberately refuses to buffer oversized bodies: GitHub's repo JSON is a few KB, so anything near 1 MB signals a wrong or malicious response, and the check on the header prevents allocating the read at all.","triggerScenarios":"A Content-Length header > 1000000 or < 0 on the response from https://api.github.com/repos/666ghj/MiroFish; a proxy returning an oversized error/captive-portal page; a test double that sets an unrealistic Content-Length.","commonSituations":"Captive portals or proxy block pages served with huge bodies; API URL changed to point at something that returns large payloads; tests that copy headers from a different endpoint.","solutions":["Verify nothing is intercepting the request (proxy, VPN, captive portal) — the real GitHub repo payload is far below 1 MB.","Confirm API_URL still targets a single repository endpoint (/repos/{owner}/{repo}) and was not repointed at a list endpoint.","In tests, set Content-Length to a realistic small value or omit it entirely (the check only runs when the header is present)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    count = fetch_star_count(token)\nexcept FetchError as exc:\n    if exc.args[0] == \"GitHub API response exceeded the size limit\":\n        # header declared an oversized body: never retry into an unknown proxy\n        raise","preventionTips":["Keep MAX_HTTP_BYTES sized to the real payload (repo JSON is ~5 KB; 1 MB is already generous).","Do not raise the limit to make an intercepted response pass — find out what is returning megabytes for a repo lookup.","Assert in CI that direct curl of the endpoint stays under a few KB so regressions surface before the script does."],"tags":["http","size-limit","fetch-star-count","proxy"],"backgroundTag":null,"analyzedSha":"b5b53acc57189a4a42e44a23e149dc655c98fe82","analyzedAt":"2026-08-14T22:29:33.146Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}