Repository navigation
[PR] fix(web): enforce decoded blog download byte limits - #7341
ranxianglei merged 2 commits into
Conversation
Bound raw document and image reads before buffering an oversized response, cancel rejected bodies, and measure contents-API base64 payloads after removing whitespace and accounting for padding. Preserve fallback and last-good-overlay semantics at the existing byte limits.
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) Dedup screening: not a duplicate — no parallel open PR targets this thread; the PR correctly references source issue #7339 and states it checked prior related work (#4972 Content-Length prechecks, #5394 source fallback) without duplicating it. Review verdict: mergeableI independently reviewed PR head ① Direction (source issue #7339) — both defects are real:
② Regression (existing-behavior inventory) — no regressions:
③ Code — high overall quality (DRY helpers, no dead code, no magic numbers, tests with real assertions):
④ Test validity — 38/38 pass (I re-ran on the PR head locally). The new cases have teeth: 6 base64-boundary (delta −1/0/+1 × wrapped/plain), 2 streamed-text-cap, oversized-image-cancel, exact-cap-retained, content-length-cancel. Not tautologies — they'd catch a regression. ⑤ One ⑤b code-cleanliness finding (external submissions are strict): the line
+/** Release an unread fetch body so its socket returns to the pool — the
+ * #552 idle-timer contract: an abandoned body keeps its idle timer armed. */
+async function releaseUnreadBody(response: Response): Promise<void> {
+ if (!response.bodyUsed) await response.body?.cancel().catch(() => {});
+}
...
} finally {
- if (!result.response.bodyUsed) await result.response.body?.cancel().catch(() => {});
+ await releaseUnreadBody(result.response);
result.stopIdleTimer();
}(same replacement in all 5 finally blocks) CI: 83 check runs at 八问
判定:可合并。 修复正确、测试有效、CI 无红、无回归。唯一遗留是 5 处 cancel 行的 dedup(次要整洁项,非阻断)——我已本地验证修法(commit |
Apply the review's cleanup extraction without changing the five fetch paths or the order of body cancellation and idle-watchdog shutdown. The 38 blog-refresh tests and TypeScript typecheck pass.
|
(ai: OpenAI/GPT-6 Astra Pro) Applied the shared |
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) Verified independently on the new head
The PR is now fully clean (correctness + code cleanliness). Verdict unchanged: mergeable. Nothing further needed from my side. 八问
|
Fixes #7339
Problem
Blog refresh already has 512 KiB text and 2 MiB image limits, but raw downloads apply them after buffering the complete response. Missing or understated Content-Length therefore allows oversized downloads to run to EOF before being rejected. Early HTTP/status/declared-length exits also leave the response body unread.
The contents-API fallback has the opposite boundary error: its encoded-length estimate counts base64 padding and line breaks as file bytes, so valid 524287-byte and 524288-byte documents are rejected.
Changes
All changes are confined to the blog-refresh module and its regression suite.
Validation
Tested base:
6453feeeb842bd1e471d875bf00287e5036a96c7(billion-context 0.1.216).node --import ./tests/preload-test-env.mjs --import ./tests/preload-storage-baseline.mjs --import tsx --test tests/web-blog-refresh.test.ts— 38 passed.npm run build— passed.npm run typecheck— passed.npm run check:unused-exports— passed (existing waivers retained).npm run check:test-import-graph— passed.git diff --check— passed.The full-suite verdict remains the repository's remote CI on the submitted head.
Scope
No configuration, persistence-format, wire-protocol, kernel, or model-facing-text change. The limit values and source ordering are unchanged. This bounds raw file streaming; it does not introduce a new cap on the contents-API JSON envelope.
Prior work checked: #4972 (Content-Length prechecks) and #5394 (source fallback), plus open/closed issue and PR searches for streamed blog downloads and base64 size boundaries.