
























@@ -286,6 +286,28 @@ describe("readRemoteMediaBuffer", () => {
286286expect(body.wasCanceled()).toBe(true);
287287});
288288289+it("rejects malformed content-length before remote buffer reads", async () => {
290+const body = makeCancelableStream([new Uint8Array([1, 2, 3, 4, 5])]);
291+const fetchImpl = vi.fn(
292+async () =>
293+new Response(body.stream, {
294+status: 200,
295+headers: { "content-length": "1e9" },
296+}),
297+);
298+299+await expect(
300+readRemoteMediaBuffer({
301+url: "https://example.com/file.bin",
302+ fetchImpl,
303+maxBytes: 4,
304+lookupFn: makeLookupFn(),
305+}),
306+).rejects.toThrow("invalid content-length header: 1e9");
307+308+expect(body.wasCanceled()).toBe(true);
309+});
310+289311it("applies a default stream limit when maxBytes is omitted", async () => {
290312const fetchImpl = vi.fn(
291313async () =>
@@ -632,6 +654,25 @@ describe("readRemoteMediaBuffer", () => {
632654expect(body.wasCanceled()).toBe(true);
633655});
634656657+it("rejects malformed content-length before saving responses", async () => {
658+const body = makeCancelableStream([new Uint8Array([1, 2, 3, 4, 5])]);
659+660+await expect(
661+saveResponseMedia(
662+new Response(body.stream, {
663+status: 200,
664+headers: { "content-length": "1e9" },
665+}),
666+{
667+maxBytes: 4,
668+sourceUrl: "https://example.com/file.bin",
669+},
670+),
671+).rejects.toThrow("invalid content-length header: 1e9");
672+673+expect(body.wasCanceled()).toBe(true);
674+});
675+635676it("decodes URL path basenames when deriving remote media filenames", async () => {
636677const fetchImpl = vi.fn(
637678async () =>
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。