From 3f7ddfebf90b3e3c04db9bf09d9d217ae38f3f60 Mon Sep 17 00:00:00 2001 From: Strycher Date: Wed, 29 Jul 2026 17:34:36 -0400 Subject: [PATCH] fix(#395): correct BLE writable floor in effectiveMaxFrameSize (Gemini review) Gemini adversarial review flagged the getter's clamp: the floor used the ATT_MTU minimum (23) where it should use the writable minimum (20 = 23-3), overstating the cap by 3 for tiny MTUs; and an unknown MTU defaulted to maxFrameSize (172), the wrong direction for a safety cap. Floor at 20 and default an unknown MTU conservatively. No behaviour change on radios that grant MTU >= 175 (they hit the maxFrameSize short-circuit). Co-Authored-By: Claude Opus 4.8 --- lib/connector/meshcore_connector.dart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index 7a470c5e..ad0d53c7 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -442,10 +442,15 @@ class MeshCoreConnector extends ChangeNotifier { return maxFrameSize; } final mtu = _device?.mtuNow ?? 0; - if (mtu <= 0) return maxFrameSize; + // ATT_MTU 23 is the BLE minimum; a single write then carries 23 - 3 = 20 + // bytes. An unknown MTU must fall back to that floor, never [maxFrameSize] — + // defaulting an unknown link to the largest size would authorize an + // oversized write (#395 review). + const minWritable = 20; + if (mtu <= 0) return minWritable; final writable = mtu - 3; if (writable >= maxFrameSize) return maxFrameSize; - return writable < 23 ? 23 : writable; + return writable < minWritable ? minWritable : writable; } String? get deviceId => _deviceId;