Skip to content

Commit

Permalink
fix: correct buffers concatenation in socket
Browse files Browse the repository at this point in the history
  • Loading branch information
shamelin committed Aug 16, 2024
1 parent 2a0d29c commit 3e353b2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions server/services/Deluge/clientRequestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,18 @@ class ClientRequestManager {
tlsSocket.on('secureConnect', () => {
tlsSocket.on('data', (chunk: Buffer) => {
if (rpcBuffer != null) {
rpcBuffer = Buffer.concat([rpcBuffer, chunk], rpcBufferSize);
rpcBuffer = Buffer.concat(
[rpcBuffer, chunk],
rpcBufferSize <= rpcBuffer.length + chunk.length ? rpcBufferSize : undefined,
);
} else {
if (chunk[0] !== DELUGE_RPC_PROTOCOL_VERSION) {
handleError(new Error('Unexpected Deluge RPC version.'));
return;
}

rpcBufferSize = chunk.slice(1, 5).readUInt32BE(0);
rpcBuffer = chunk.slice(5);
rpcBufferSize = chunk.subarray(1, 5).readUInt32BE(0);
rpcBuffer = chunk.subarray(5);
}

if (rpcBuffer.length >= rpcBufferSize) {
Expand Down

0 comments on commit 3e353b2

Please sign in to comment.