Skip to content

Commit

Permalink
Skip processing partial message (SOHU-Co#1051)
Browse files Browse the repository at this point in the history
  • Loading branch information
verakruhliakova authored and corlobepy committed May 24, 2019
1 parent a231ccf commit cf98ca8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/protocol/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,13 @@ function decodeMessageSet (topic, partition, messageSet, cb, maxTickMessages, hi
const messageSetSize = messageSet.length;
while (messageSet.length > 0) {
var cur = 8 + 4 + 4 + 1 + 1 + 4 + 4;
var partial = false;
Binary.parse(messageSet)
.word64bs('offset')
.word32bs('messageSize')
.tap(function (vars) {
if (vars.messageSize > messageSet.length - 12) {
vars.partial = true;
partial = true;
}
})
.word32bs('crc')
Expand Down Expand Up @@ -214,7 +215,7 @@ function decodeMessageSet (topic, partition, messageSet, cb, maxTickMessages, hi
return;
}

if (!vars.partial && vars.offset !== null) {
if (!partial && vars.offset !== null) {
messageCount++;
set.push(vars.offset);
if (!cb) return;
Expand All @@ -241,6 +242,8 @@ function decodeMessageSet (topic, partition, messageSet, cb, maxTickMessages, hi
});
}
});
// Skip decoding binary left in the message set if partial message detected
if (partial) break;
// Defensive code around potential denial of service
if (maxTickMessages && messageCount > maxTickMessages) break;
messageSet = messageSet.slice(cur);
Expand Down

0 comments on commit cf98ca8

Please sign in to comment.