From f436acb2a7deba7b3f6fab7968631d839651eaa4 Mon Sep 17 00:00:00 2001 From: Mohammad Abdul Sahil <127765312+abdulsaheel@users.noreply.github.com> Date: Sat, 5 Dec 2026 13:21:33 +0530 Subject: [PATCH] gen5 historical: reject non-0x2f packet types --- lib/src/gen5_records.dart | 3 +++ test/gen5_historical_test.dart | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/src/gen5_records.dart b/lib/src/gen5_records.dart index a585ff6..25ff867 100644 --- a/lib/src/gen5_records.dart +++ b/lib/src/gen5_records.dart @@ -34,6 +34,7 @@ import 'dart:typed_data'; +import 'constants.dart' show PacketType; import 'records.dart' show kMinRrMs, kMaxRrMs; ByteData _view(Uint8List b) => @@ -1869,6 +1870,8 @@ const List kGen5HistoricalDecoders = [ /// those, exactly like `parseR24`'s null contract. Gen5HistoricalRecord? parseGen5Historical(Uint8List inner) { if (inner.length < 11) return null; // shorter than the shared header itself + // inner[1] is the sequence byte on a control frame; same trap parseR24 gates. + if (inner[0] != PacketType.historicalData) return null; if (_v21Decoder.matches(inner)) return _v21Decoder.decode(inner); diff --git a/test/gen5_historical_test.dart b/test/gen5_historical_test.dart index 2bbbb1b..fabb632 100644 --- a/test/gen5_historical_test.dart +++ b/test/gen5_historical_test.dart @@ -931,4 +931,17 @@ void main() { }); } }); + + test('parseGen5Historical ignores non-record packet types', () { + for (final t in [ + PacketType.consoleLogs, + PacketType.commandResponse, + PacketType.event, + ]) { + final inner = Uint8List(112); + inner[0] = t; + inner[1] = 18; // seq byte that looks like a v18 version + expect(parseGen5Historical(inner), isNull, reason: 'type 0x${t.toRadixString(16)}'); + } + }); }