restify / restify/node-restify
bodyReader does not work with both gunzip and maxBodySize
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.7k
- Forks
- 975
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 5
Description
Bug Report
bodyReader plugin setup with maxBodySize when called with Content-Encoding: gzip with body size over the body limit causes zlib buffer error and eventually stops process.
Restify Version
8.3.2
Node.js Version
10.14.2
Expected behaviour
Return "413 Body Too Long". Same behaviour as for not gzipped content.
Actual behaviour
server is down with error:
events.js:167
throw er; // Unhandled 'error' event
^
Error: unexpected end of file
at Zlib.zlibOnError [as onerror] (zlib.js:154:17)
Emitted 'error' event at:
at Zlib.zlibOnError [as onerror] (zlib.js:157:8)
Repro case
'use strict';
const restify = require('restify');
const got = require('got');
const zlib = require('zlib');
const payload = { apple: 'red' };
const body = zlib.gzipSync(JSON.stringify(payload));
// set maxBodySize smaller than gzipped body
const maxBodySize = body.byteLength - 1;
const server = restify.createServer();
server.listen(3000, '127.0.0.1');
server.use(restify.plugins.bodyParser({ maxBodySize }));
server.post('/foo', (req, res, next) => {
res.send();
next();
});
got({
url: 'http://127.0.0.1:3000/foo',
body,
json: false,
throwHttpErrors: false,
headers: {
'Content-Encoding': 'gzip',
'Content-Type': 'application/json'
}
})
.then(response => console.log(response.statusCode))
.catch(err => console.log(err));
Cause
bodyReader done handler function is not triggered when gunzip transformer emits error due to incomplete buffer when it is incomplete because maxBodySize limit was reached.
Are you willing and able to fix this?
Yes. PR is on the way.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the bodyParser/bodyReader path, especially the done handler and gunzip transformer error handling described in the issue. Reproduce the supplied maxBodySize and Content-Encoding: gzip case; done means the request returns 413 Body Too Long without the process stopping.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100