11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ci// This test ensures that zlib throws a RangeError if the final buffer needs to 51cb0ef41Sopenharmony_ci// be larger than kMaxLength and concatenation fails. 61cb0ef41Sopenharmony_ci// https://github.com/nodejs/node/pull/1811 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst assert = require('assert'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci// Change kMaxLength for zlib to trigger the error without having to allocate 111cb0ef41Sopenharmony_ci// large Buffers. 121cb0ef41Sopenharmony_ciconst buffer = require('buffer'); 131cb0ef41Sopenharmony_ciconst oldkMaxLength = buffer.kMaxLength; 141cb0ef41Sopenharmony_cibuffer.kMaxLength = 64; 151cb0ef41Sopenharmony_ciconst zlib = require('zlib'); 161cb0ef41Sopenharmony_cibuffer.kMaxLength = oldkMaxLength; 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ciconst encoded = Buffer.from('H4sIAAAAAAAAA0tMHFgAAIw2K/GAAAAA', 'base64'); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci// Async 211cb0ef41Sopenharmony_cizlib.gunzip(encoded, function(err) { 221cb0ef41Sopenharmony_ci assert.ok(err instanceof RangeError); 231cb0ef41Sopenharmony_ci}); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci// Sync 261cb0ef41Sopenharmony_ciassert.throws(function() { 271cb0ef41Sopenharmony_ci zlib.gunzipSync(encoded); 281cb0ef41Sopenharmony_ci}, RangeError); 29