Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultipartReader creates broken files #4864

Closed
marcosc90 opened this issue Apr 23, 2020 · 0 comments · Fixed by #4865
Closed

MultipartReader creates broken files #4864

marcosc90 opened this issue Apr 23, 2020 · 0 comments · Fixed by #4865

Comments

@marcosc90
Copy link
Contributor

marcosc90 commented Apr 23, 2020

MultipartReader truncates big files.

version:

deno 0.41.0
v8 8.2.308
typescript 3.8.3

To reproduce run the following snippet:

import { serve } from "https://deno.land/std/http/server.ts";
import { MultipartReader } from "https://deno.land/std/mime/multipart.ts";

function getHeaderValueParams(value) {
  const params = new Map();
  // Forced to do so for some Map constructor param mismatch
  value
    .split(";")
    .slice(1)
    .map((s) => s.trim().split("="))
    .filter((arr) => arr.length > 1)
    .map(([k, v]) => [k, v.replace(/^"([^"]*)"$/, "$1")])
    .forEach(([k, v]) => params.set(k, v));
  return params;
}

const s = serve({ port: 8000 });
for await (const req of s) {
    const params = getHeaderValueParams(req.headers.get("content-type"))
    
    const reader = new MultipartReader(req.body, params.get('boundary'));

    const form = await reader.readForm(1 << 20)
    console.log(form.file('file'))
    req.respond({ body: 'deno' });
}

Any file with a size bigger than 11534332 bytes will get truncated.

truncate -s 12m 12m.file

curl --location --request POST 'http://localhost:8000/' \
--form 'deno=land' \
--form 'file=@/home/marcos/12mb.file'
# change file path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant