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

RangeError: Attempt to allocate Buffer larger than maximum size: 0x3fffffff bytes #123

Closed
meetwudi opened this issue Nov 3, 2014 · 7 comments

Comments

@meetwudi
Copy link

meetwudi commented Nov 3, 2014

I am using node-webkit with qiniu/nodejs-sdk. I am uploading an 7KB image with following code, almost identical to the code in examples.

  function getUploadToken(bucketName) {
    var putPolicy = new qiniu.rs.PutPolicy(bucketName);
    return putPolicy.token();
  }
  function uploadFile(localFile, key) {
    var extra = new qiniu.io.PutExtra(),
      token = getUploadToken($('#bucket_name').val());

    qiniu.io.putFile(token, key, localFile, extra, function(err, ret) {
      if(!err) {
        console.log(ret.key, ret.hash);
      } else {
        console.log(err);
      }
    });
  }

But when I try to upload the image, I got a RangeError: Attempt to allocate Buffer larger than maximum size: 0x3fffffff bytes.
screen shot 2014-11-03 at 6 39 25 pm

@longbai
Copy link
Contributor

longbai commented Nov 3, 2014

收到,我们会看下。

@meetwudi
Copy link
Author

meetwudi commented Nov 3, 2014

Sorry, it is my fault. I passed a number as key to putFile. This may cause formstream.field to crash. But I think it should be guarded though, because it is quite common to use timestamp Date.now() as the key :) @fengmk2 @longbai

@meetwudi meetwudi closed this as completed Nov 3, 2014
@fengmk2
Copy link
Contributor

fengmk2 commented Nov 3, 2014

Oh maybe I need to supports number field

@meetwudi
Copy link
Author

meetwudi commented Nov 3, 2014

@fengmk2 It would be nice.

fengmk2 added a commit to node-modules/formstream that referenced this issue Nov 4, 2014
JacksonTian added a commit to JacksonTian/node that referenced this issue Jan 7, 2016
Buffer constructor has too much behaviour.

it is usual to convert string to Buffer in the form of new
Buffer(str).

If don't check type of first argument, new Buffer(number) can lead
Buffer vulnerability. For example:

- https://github.com/websockets/ws/releases/tag/1.0.1
- qiniu/nodejs-sdk#123

Introduce Buffer.encode() method to be explicit abort encoding.
@douxing
Copy link

douxing commented Apr 27, 2016

@longbai @fengmk2 this bug has NOT been fixed because your package.json file still use 0.0.7 version of formstream, will you update it to the latest version of formstream, to make qiniu node sdk suports number fields?

@longbai
Copy link
Contributor

longbai commented Apr 27, 2016

@douxing 我们看下

@douxing
Copy link

douxing commented Apr 28, 2016

@longbai 感谢

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

4 participants