From 32ed48e037469e1936f6bd9f827dfbd8e2ce51ee Mon Sep 17 00:00:00 2001 From: Tom Fitzhenry Date: Thu, 27 Aug 2026 23:50:01 +0000 Subject: [PATCH] fix: cap advertised max buffer size at 2^24 - 1 The 16 MiB constant (16 << 20) is exactly 2^24, but the serprog length field is 24-bit little-endian, so it wrapped to zero: QWrNMaxLen and QRdNMaxLen replied with a maximum length of 0. Use 2^24 - 1 so the advertised maximum is representable. --- serprog/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/serprog/src/lib.rs b/serprog/src/lib.rs index d060744..8205d24 100644 --- a/serprog/src/lib.rs +++ b/serprog/src/lib.rs @@ -38,7 +38,8 @@ fn le_u24_to_u32(bytes: &[u8]) -> u32 { const S_ACK: u8 = 0x06; const S_NAK: u8 = 0x15; -const MAX_BUFFER_SIZE: usize = 16 << 20; +// 16 MiB minus one: the protocol's 24-bit length field cannot express 2^24. +const MAX_BUFFER_SIZE: usize = (16 << 20) - 1; #[derive(FromBytes, IntoBytes, Unaligned, Immutable)] #[repr(C, packed)]