Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger error on pako inflate frame failure with inflate status #19

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/protocol/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@ Stream.prototype._writeUpstream = function _writeUpstream(frame) {
return moreNeeded;
};

var inflateStatusToName = {
"0": "Z_OK",
"1": "Z_STREAM_END",
"2": "Z_SYNC_FLUSH",
"-1": "ERRNO",
"-2": "STREAM_ERROR",
"-3": "DATA_ERROR",
"-4": "MEM_ERROR"
};

// The `_receive` method (= `upstream._receive`) gets called when there's an incoming frame.
Stream.prototype._receive = function _receive(frame, ready) {
// * If it's a DATA frame, then push the payload into the output buffer on the other side.
Expand All @@ -296,6 +306,14 @@ Stream.prototype._receive = function _receive(frame, ready) {
}
var data = frame.data;
this.pakoInf.push(data, frame.END_STREAM);

if (this.pakoInf.err < 0) {
var statusName = inflateStatusToName[this.pakoInf.err];
var inflateError = new Error('Inflate frame failed with status ' + statusName);
this._log.error(inflateError, inflateError.message);
this.reset(inflateError);
this.emit('error', inflateError);
}
}
else
{
Expand Down