Skip to content

Commit

Permalink
fix: correct buffers concatenation in socket (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
shamelin authored Aug 19, 2024
1 parent 2a0d29c commit cc2c24f
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 cc2c24f

Please sign in to comment.