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

Parser seems to truncate values over 0x7F from body attribs #37

Closed
gdw2 opened this issue Dec 10, 2013 · 3 comments
Closed

Parser seems to truncate values over 0x7F from body attribs #37

gdw2 opened this issue Dec 10, 2013 · 3 comments

Comments

@gdw2
Copy link

gdw2 commented Dec 10, 2013

(Originally posted here: expressjs/express#1855)

Below is a small illustration. In both cases I'm sending 4 bytes. In the first case (which has a value over 0x7F), the size is incorrectly reported as '1'. In the second case (no values over 0x7F), it is correctly reported as '4' and all the data is intact.

Server:

app.post('/api', multipartMiddleware, function(req, res){
    var body = req.body.name;
    console.log('body',req.body);
    console.log('req body len', body.length);
    res.send("respond with a resource");
});

Python test client:

>>> requests.post('http://localhost:3000/api', files={'file':open('foo','rb')}, data={'name':pack('!HH',0xF0,0x0)})
<Response [200]>
>>> requests.post('http://localhost:3000/api', files={'file':open('foo','rb')}, data={'name':pack('!HH',0x0F,0x0)})
<Response [200]>

Express output:

Express server listening on port 3000
body { name: '\u0000' }
req body len 1
POST /api 200 9ms - 23b

body { name: '\u0000\u000f\u0000\u0000' }
req body len 4
POST /api 200 3ms - 23b
@andrewrk
Copy link
Collaborator

This looks like a rather nasty bug. Thanks for the report. Feel free to start working on a fix and make a pull request; otherwise I'll get around to it eventually.

@gdw2
Copy link
Author

gdw2 commented Dec 11, 2013

It looks like I just need to be extra vigilant at setting the encoding (which defaults to utf8) to 'binary' in all the required places, such as...

var form = new multiparty.Form({'encoding':'binary'});

Case closed.

@gdw2 gdw2 closed this as completed Dec 11, 2013
@andrewrk
Copy link
Collaborator

ah, I should have known that. Thanks. It's been a while since I've messed with this stuff; my head is full of audio-processing and 3D graphics lately :)

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

No branches or pull requests

2 participants