From a9f9ef95e8a1fc76c413a6f5ac55d0cbe2250a57 Mon Sep 17 00:00:00 2001 From: Tal Aloni Date: Fri, 1 Mar 2024 10:55:52 +0200 Subject: [PATCH] SMB2Client: Support non-Microsoft servers returning MaxReadSize > MaxTransactSize --- SMBLibrary/Client/SMB2Client.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/SMBLibrary/Client/SMB2Client.cs b/SMBLibrary/Client/SMB2Client.cs index ce87e29..4486e9a 100644 --- a/SMBLibrary/Client/SMB2Client.cs +++ b/SMBLibrary/Client/SMB2Client.cs @@ -1,4 +1,4 @@ -/* Copyright (C) 2017-2023 Tal Aloni . All rights reserved. +/* Copyright (C) 2017-2024 Tal Aloni . All rights reserved. * * You can redistribute this program and/or modify it under the terms of * the GNU Lesser Public License as published by the Free Software Foundation, @@ -481,9 +481,12 @@ namespace SMBLibrary.Client NegotiateResponse negotiateResponse = (NegotiateResponse)command; if ((negotiateResponse.Capabilities & Capabilities.LargeMTU) > 0) { - // [MS-SMB2] 3.2.5.1 Receiving Any Message - If the message size received exceeds Connection.MaxTransactSize, the client MUST disconnect the connection. - // Note: Windows clients do not enforce the MaxTransactSize value, we add 256 bytes. - int maxPacketSize = SessionPacket.HeaderLength + (int)Math.Min(negotiateResponse.MaxTransactSize, ClientMaxTransactSize) + 256; + // [MS-SMB2] 3.2.5.1 Receiving Any Message - If the message size received exceeds Connection.MaxTransactSize, the client SHOULD disconnect the connection. + // Note: Windows clients do not enforce the MaxTransactSize value. + // We use a value that we have observed to work well with both Microsoft and non-Microsoft servers. + // see https://github.com/TalAloni/SMBLibrary/issues/239 + int serverMaxTransactSize = (int)Math.Max(negotiateResponse.MaxTransactSize, negotiateResponse.MaxReadSize); + int maxPacketSize = SessionPacket.HeaderLength + (int)Math.Min(serverMaxTransactSize, ClientMaxTransactSize) + 256; if (maxPacketSize > state.ReceiveBuffer.Buffer.Length) { state.ReceiveBuffer.IncreaseBufferSize(maxPacketSize);