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

Fixup few things after latest rebase #2003

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Readable = Stream.Readable;
const Writable = Stream.Writable;

const kMinPoolSpace = 128;
const kMaxLength = process.binding('smalloc').kMaxLength;
const kMaxLength = require('buffer').kMaxLength;

const O_APPEND = constants.O_APPEND || 0;
const O_CREAT = constants.O_CREAT || 0;
Expand Down
12 changes: 2 additions & 10 deletions lib/internal/buffer_new.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const internalUtil = require('internal/util');
exports.Buffer = Buffer;
exports.SlowBuffer = SlowBuffer;
exports.INSPECT_MAX_BYTES = 50;
exports.kMaxLength = binding.kMaxLength;


Buffer.poolSize = 8 * 1024;
Expand Down Expand Up @@ -456,16 +457,7 @@ Buffer.prototype.write = function(string, offset, length, encoding) {

// XXX legacy write(string, encoding, offset, length) - remove in v0.13
} else {
if (!writeWarned) {
if (process.throwDeprecation)
throw new Error(writeMsg);
else if (process.traceDeprecation)
console.trace(writeMsg);
else
console.error(writeMsg);
writeWarned = true;
}

writeWarned = internalUtil.printDeprecationMessage(writeMsg, writeWarned);
var swap = encoding;
encoding = offset;
offset = length >>> 0;
Expand Down
1 change: 1 addition & 0 deletions lib/internal/buffer_old.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const kMaxLength = smalloc.kMaxLength;
exports.Buffer = Buffer;
exports.SlowBuffer = SlowBuffer;
exports.INSPECT_MAX_BYTES = 50;
exports.kMaxLength = binding.kMaxLength;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it exposed only for tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's exposed because other libs like zlib need that value to know whether to error or not. Without it those libs wouldn't work properly in old buffer mode.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it can be internal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exposing kMaxLength does keep parody with how it's exposed today via smalloc. and IIRC it was also exposed before smalloc.

That value is more useful for users now because the maximum size of allocation depends on the architecture. So serves as a preemptive means to prevent an exception.

In reality I don't care that much, but it would make testing more difficult.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok then. I wanted to expose it as well but @bnoordhuis said it will probably become irrelevant soon: #1822 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size limit of ArrayBuffer no longer exists, but number of array indices on a typed array are still constrained. I believe his comment originated from my original belief that typed arrays had no upper limit as well. That was my bad.



Buffer.poolSize = 8 * 1024;
Expand Down
2 changes: 1 addition & 1 deletion lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Transform = require('_stream_transform');
const binding = process.binding('zlib');
const util = require('util');
const assert = require('assert').ok;
const kMaxLength = process.binding('smalloc').kMaxLength;
const kMaxLength = require('buffer').kMaxLength;
const kRangeErrorMessage = 'Cannot create final Buffer. ' +
'It would be larger than 0x' + kMaxLength.toString(16) + ' bytes.';

Expand Down
11 changes: 11 additions & 0 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::Handle;
using v8::HandleScope;
using v8::Integer;
using v8::Isolate;
using v8::Local;
using v8::Maybe;
Expand Down Expand Up @@ -1156,6 +1157,16 @@ void Initialize(Handle<Object> target,
env->SetMethod(target, "writeDoubleLE", WriteDoubleLE);
env->SetMethod(target, "writeFloatBE", WriteFloatBE);
env->SetMethod(target, "writeFloatLE", WriteFloatLE);

uint32_t kMaxLength;
if (sizeof(int32_t) == sizeof(intptr_t) || using_old_buffer) {
kMaxLength = 0x3fffffff;
} else {
kMaxLength = 0x7fffffff;
}
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "kMaxLength"),
Integer::NewFromUnsigned(env->isolate(), kMaxLength)).FromJust();
}


Expand Down
11 changes: 6 additions & 5 deletions test/parallel/test-regress-GH-io-1811.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

const assert = require('assert');

// Change kMaxLength for zlib to trigger the error
// without having to allocate 1GB of buffers
const smalloc = process.binding('smalloc');
smalloc.kMaxLength = 128;
// Change kMaxLength for zlib to trigger the error without having to allocate
// large Buffers.
const buffer = require('buffer');
const oldkMaxLength = buffer.kMaxLength;
buffer.kMaxLength = 128;
const zlib = require('zlib');
smalloc.kMaxLength = 0x3fffffff;
buffer.kMaxLength = oldkMaxLength;

const encoded = new Buffer('H4sIAAAAAAAAA0tMHFgAAIw2K/GAAAAA', 'base64');

Expand Down