diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2013-01-22 13:23:46 +0100 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2013-01-22 13:34:43 +0100 |
commit | d7bf7ed9935587a6681a090e5d12840f9a60f55e (patch) | |
tree | e42875903c67c12f59f3e74bfbd489ec5f8f2d7e /src | |
parent | 1c32eb4ae227f09e0e442ecd0445ec34d85332fe (diff) | |
download | node-d7bf7ed9935587a6681a090e5d12840f9a60f55e.tar.gz |
zlib: don't assert on malformed dictionary
Handle Z_DATA_ERROR errors from inflateSetDictionary() gracefully.
Fixes the following assertion:
node: ../src/node_zlib.cc:167: static void node::ZCtx::Process
(uv_work_t*): Assertion `ctx->err_ == 0 && "Failed to set
dictionary"' failed.
Aborted (core dumped)
Fixes #4632.
Diffstat (limited to 'src')
-rw-r--r-- | src/node_zlib.cc | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/node_zlib.cc b/src/node_zlib.cc index 3674919d4..deacb713d 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -163,12 +163,16 @@ class ZCtx : public ObjectWrap { ctx->err_ = inflateSetDictionary(&ctx->strm_, ctx->dictionary_, ctx->dictionary_len_); - // TODO Handle Z_DATA_ERROR, wrong dictionary - assert(ctx->err_ == Z_OK && "Failed to set dictionary"); if (ctx->err_ == Z_OK) { // And try to decode again ctx->err_ = inflate(&ctx->strm_, ctx->flush_); + } else if (ctx->err_ == Z_DATA_ERROR) { + + // Both inflateSetDictionary() and inflate() return Z_DATA_ERROR. + // Make it possible for After() to tell a bad dictionary from bad + // input. + ctx->err_ = Z_NEED_DICT; } } break; @@ -196,7 +200,11 @@ class ZCtx : public ObjectWrap { // normal statuses, not fatal break; case Z_NEED_DICT: - ZCtx::Error(ctx, "Missing dictionary"); + if (ctx->dictionary_ == NULL) { + ZCtx::Error(ctx, "Missing dictionary"); + } else { + ZCtx::Error(ctx, "Bad dictionary"); + } return; default: // something else. |