mirror of
https://github.com/nodejs/node.git
synced 2025-05-09 19:16:58 +00:00

Starting in V8 v4.3 the maximum array index of a typed array is the same as the largest Smi supported on a given architecture. To compensate for these differences export kMaxLength from the buffer module with the correct size for the given architecture. PR-URL: https://github.com/nodejs/io.js/pull/2003 Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
24 lines
557 B
JavaScript
24 lines
557 B
JavaScript
'use strict';
|
|
|
|
const assert = require('assert');
|
|
|
|
// 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');
|
|
buffer.kMaxLength = oldkMaxLength;
|
|
|
|
const encoded = new Buffer('H4sIAAAAAAAAA0tMHFgAAIw2K/GAAAAA', 'base64');
|
|
|
|
// Async
|
|
zlib.gunzip(encoded, function(err) {
|
|
assert.ok(err instanceof RangeError);
|
|
});
|
|
|
|
// Sync
|
|
assert.throws(function() {
|
|
zlib.gunzipSync(encoded);
|
|
}, RangeError);
|