-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zlib: prevent uncaught exception in zlibBuffer
If the accumulation of data for the final Buffer is greater than kMaxLength it will throw an un-catchable RangeError. Instead now pass the generated error to the callback. PR-URL: #1811 Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
- Loading branch information
1 parent
953b3e7
commit 3806d87
Showing
2 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
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; | ||
const zlib = require('zlib'); | ||
smalloc.kMaxLength = 0x3fffffff; | ||
|
||
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); |