From f21739bc110294ef7ac315b524b21ca6f5915222 Mon Sep 17 00:00:00 2001 From: Mohammad Abdul Sahil <127765312+abdulsaheel@users.noreply.github.com> Date: Sat, 5 Dec 2026 13:21:25 +0530 Subject: [PATCH 1/2] huami legacy: refuse fetch start with a zero or rolled-over date --- lib/src/huami_legacy.dart | 12 +++++++++++- test/huami_legacy_test.dart | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/src/huami_legacy.dart b/lib/src/huami_legacy.dart index 72b200a..c685e8c 100644 --- a/lib/src/huami_legacy.dart +++ b/lib/src/huami_legacy.dart @@ -97,7 +97,17 @@ const int kHuamiMaxFetchCount = 129600; if (count > kHuamiMaxFetchCount) return null; if (b.length < 15) return null; final tz = b[14] >= 0x80 ? b[14] - 0x100 : b[14]; - final wall = DateTime.utc(b[7] | (b[8] << 8), b[9], b[10], b[11], b[12], b[13]); + final year = b[7] | (b[8] << 8); + final wall = DateTime.utc(year, b[9], b[10], b[11], b[12], b[13]); + // an unclocked band sends zeros; month 13 / feb 31 would silently roll over. + if (year < 2000 || + wall.month != b[9] || + wall.day != b[10] || + wall.hour != b[11] || + wall.minute != b[12] || + wall.second != b[13]) { + return null; + } return ( count: count, startSec: wall.millisecondsSinceEpoch ~/ 1000 - tz * 15 * 60, diff --git a/test/huami_legacy_test.dart b/test/huami_legacy_test.dart index 199a1d7..7765a10 100644 --- a/test/huami_legacy_test.dart +++ b/test/huami_legacy_test.dart @@ -34,6 +34,15 @@ void main() { expect(parseHuamiFetchStart([0x10, 0x01, 0x02]), isNull); }); + test('start response: implausible or rolled-over date is refused', () { + List f(int y, int mo, int d) => + [0x10, 0x01, 0x01, 60, 0, 0, 0, y & 0xff, y >> 8, mo, d, 0, 0, 0, 0]; + expect(parseHuamiFetchStart(f(0, 0, 0)), isNull); + expect(parseHuamiFetchStart(f(2026, 13, 1)), isNull); + expect(parseHuamiFetchStart(f(2026, 2, 31)), isNull); + expect(parseHuamiFetchStart(f(2026, 10, 3)), isNotNull); + }); + test('samples: kind inheritance, no-reading HR, minute timestamps', () { final buf = HuamiActivityBuffer() ..add([0, 0x09, 10, 0, 55, 0x00, 5, 0, 0xff]) From 7fde351096e95e2fc100431731546215193b94ed Mon Sep 17 00:00:00 2001 From: Mohammad Abdul Sahil <127765312+abdulsaheel@users.noreply.github.com> Date: Sat, 5 Dec 2026 20:46:11 +0530 Subject: [PATCH 2/2] huami legacy: cap fetch start year at 2100 --- lib/src/huami_legacy.dart | 1 + test/huami_legacy_test.dart | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/src/huami_legacy.dart b/lib/src/huami_legacy.dart index c685e8c..b7df2ec 100644 --- a/lib/src/huami_legacy.dart +++ b/lib/src/huami_legacy.dart @@ -101,6 +101,7 @@ const int kHuamiMaxFetchCount = 129600; final wall = DateTime.utc(year, b[9], b[10], b[11], b[12], b[13]); // an unclocked band sends zeros; month 13 / feb 31 would silently roll over. if (year < 2000 || + year > 2100 || wall.month != b[9] || wall.day != b[10] || wall.hour != b[11] || diff --git a/test/huami_legacy_test.dart b/test/huami_legacy_test.dart index 7765a10..2532123 100644 --- a/test/huami_legacy_test.dart +++ b/test/huami_legacy_test.dart @@ -38,6 +38,7 @@ void main() { List f(int y, int mo, int d) => [0x10, 0x01, 0x01, 60, 0, 0, 0, y & 0xff, y >> 8, mo, d, 0, 0, 0, 0]; expect(parseHuamiFetchStart(f(0, 0, 0)), isNull); + expect(parseHuamiFetchStart(f(65535, 1, 1)), isNull); expect(parseHuamiFetchStart(f(2026, 13, 1)), isNull); expect(parseHuamiFetchStart(f(2026, 2, 31)), isNull); expect(parseHuamiFetchStart(f(2026, 10, 3)), isNotNull);