1'use strict'; 2require('../common'); 3 4// This test ensures that zlib throws a RangeError if the final buffer needs to 5// be larger than kMaxLength and concatenation fails. 6// https://github.com/nodejs/node/pull/1811 7 8const assert = require('assert'); 9 10// Change kMaxLength for zlib to trigger the error without having to allocate 11// large Buffers. 12const buffer = require('buffer'); 13const oldkMaxLength = buffer.kMaxLength; 14buffer.kMaxLength = 64; 15const zlib = require('zlib'); 16buffer.kMaxLength = oldkMaxLength; 17 18const encoded = Buffer.from('G38A+CXCIrFAIAM=', 'base64'); 19 20// Async 21zlib.brotliDecompress(encoded, function(err) { 22 assert.ok(err instanceof RangeError); 23}); 24 25// Sync 26assert.throws(function() { 27 zlib.brotliDecompressSync(encoded); 28}, RangeError); 29