X Tutup
The Wayback Machine - https://web.archive.org/web/20210116143857/https://github.com/restify/node-restify/issues/1819
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

multipartBodyParser crash if mapping files array #1819

Open
guoyibj opened this issue Mar 16, 2020 · 1 comment
Open

multipartBodyParser crash if mapping files array #1819

guoyibj opened this issue Mar 16, 2020 · 1 comment

Comments

@guoyibj
Copy link

@guoyibj guoyibj commented Mar 16, 2020

  • Used appropriate template for the issue type
  • Searched both open and closed issues for duplicates of this issue
  • Title adequately and concisely reflects the feature or the bug

Bug Report

Restify Version

8.5.1

Node.js Version

v10.15.1

Expected behaviour

No crash

Actual behaviour

Crash stack:
NodeError: The "path" argument must be one of type string, Buffer, or URL. Received type undefined
at Object.readFile (fs.js:297:3)
at forEach (/Users/guoyi/git/testServer/node_modules/restify/lib/plugins/multipartBodyParser.js:120:28)
at Array.forEach ()
at parse (/Users/guoyi/git/testServer/node_modules/restify/lib/plugins/multipartBodyParser.js:115:40)
at IncomingForm. (/Users/guoyi/git/testServer/node_modules/formidable/lib/incoming_form.js:107:9)
at IncomingForm.emit (events.js:189:13)
at IncomingForm._maybeEnd (/Users/guoyi/git/testServer/node_modules/formidable/lib/incoming_form.js:557:8)
at /Users/guoyi/git/testServer/node_modules/formidable/lib/incoming_form.js:238:12
at WriteStream. (/Users/guoyi/git/testServer/node_modules/formidable/lib/file.js:79:5)
at Object.onceWrapper (events.js:277:13)

Repro case

server side:

const restify = require('restify');

const server = restify.createServer({
name: 'Test Server',
maxParamLength: 1024,
});

server.use(restify.plugins.queryParser({ mapParams: false }));
server.use(restify.plugins.bodyParser({
mapParams: true,
mapFiles: true,
multiples: true,
}));

server.post("/files/upload", async (request, response) => {
return response.status(200).send(requst.url);
});

server.listen(3000, () => console.log(Server started on port 3000));

client side:

async function addAttachment(folder, files) {
const url = http://localhost:3000/files/upload;

const headers = {
host: hostname,
'contentType': 'multipart/form-data',
};

const formData = {
folder,
files: files.map((file) => fs.createReadStream(file)),
};

return new Promise((resolve, reject) => {
request.post({
url,
headers,
formData,
}, (err, httpResponse, body) => {
if (err) {
return reject(err);
}
if (httpResponse.statusCode === 200){
return resolve(body);
}
return reject(new Error('Unkown error'));
});
});
}

Cause

https://github.com/restify/node-restify/blob/master/lib/plugins/multipartBodyParser.js
line 120, not check array

Are you willing and able to fix this?

No

guoyibj added a commit to guoyibj/node-restify that referenced this issue Mar 16, 2020
@guoyibj guoyibj changed the title multipartBodyParser crash if mapFiles is true multipartBodyParser crash if mapping files array Mar 16, 2020
@guoyibj
Copy link
Author

@guoyibj guoyibj commented Jun 30, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.
X Tutup