Skip to content

Commit

Permalink
fix #2419 - fix RESP2 array decoder in edge cases (#2424)
Browse files Browse the repository at this point in the history
  • Loading branch information
leibale authored Feb 24, 2023
1 parent 63e5228 commit e95b258
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/client/lib/client/RESP2/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ export default class RESP2Decoder {
this.arrayItemType = undefined;

if (length === -1) {
return this.returnArrayReply(null, arraysToKeep);
return this.returnArrayReply(null, arraysToKeep, chunk);
} else if (length === 0) {
return this.returnArrayReply([], arraysToKeep);
return this.returnArrayReply([], arraysToKeep, chunk);
}

this.arraysInProcess.push({
Expand Down Expand Up @@ -235,20 +235,23 @@ export default class RESP2Decoder {
}
}

private returnArrayReply(reply: ArrayReply, arraysToKeep: number): ArrayReply | undefined {
private returnArrayReply(reply: ArrayReply, arraysToKeep: number, chunk?: Buffer): ArrayReply | undefined {
if (this.arraysInProcess.length <= arraysToKeep) return reply;

return this.pushArrayItem(reply, arraysToKeep);
return this.pushArrayItem(reply, arraysToKeep, chunk);
}

private pushArrayItem(item: Reply, arraysToKeep: number): ArrayReply | undefined {
private pushArrayItem(item: Reply, arraysToKeep: number, chunk?: Buffer): ArrayReply | undefined {
const to = this.arraysInProcess[this.arraysInProcess.length - 1]!;
to.array[to.pushCounter] = item;
if (++to.pushCounter === to.array.length) {
return this.returnArrayReply(
this.arraysInProcess.pop()!.array,
arraysToKeep
arraysToKeep,
chunk
);
} else if (chunk && chunk.length > this.cursor) {
return this.parseArray(chunk, arraysToKeep);
}
}
}

0 comments on commit e95b258

Please sign in to comment.