Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/import/noop_backup_import.dart
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,10 @@ class NoopBackupImporter {
try {
r = await src.rawQuery(
'SELECT ts FROM $t WHERE deviceId = ? AND ts >= ? '
'ORDER BY ts LIMIT 1',
[d, to]);
'AND ts <= ? ORDER BY ts LIMIT 1',
// Same upper bound as [_span]: one microsecond-scaled
// row would otherwise land here and overflow DateTime.
[d, to, noopMaxPlausibleTs()]);
} catch (e) {
if (!_isCorruptPageError(e)) rethrow;
corrupt.add(t);
Expand Down
25 changes: 25 additions & 0 deletions test/noop_backup_import_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,31 @@ void main() {
expect(res.rows, 300, reason: 'the good rows import, the corrupt one does not');
}, timeout: const Timeout(Duration(minutes: 5)));

test('a microsecond timestamp after the last day does not crash the walk',
() async {
// The jump-to-next-day probe had no upper bound, so a trailing 1.7e15 row
// reached DateTime and threw a RangeError before the last day derived.
const t0 = 1787256000; // 2026-08-20 noon UTC, a day no other fixture uses
final path = p.join(tmp.path, 'micro.sqlite');
if (File(path).existsSync()) File(path).deleteSync();
final src = await databaseFactory.openDatabase(path);
await src.execute('CREATE TABLE hrSample (deviceId TEXT, ts INTEGER, '
'bpm INTEGER, PRIMARY KEY (deviceId, ts))');
final b = src.batch();
for (var i = 0; i < 300; i++) {
b.insert('hrSample', {'deviceId': 'd', 'ts': t0 + i, 'bpm': 62});
}
b.insert('hrSample', {'deviceId': 'd', 'ts': 1700000000000000, 'bpm': 60});
await b.commit(noResult: true);
await src.close();
final bak = writeBackup('micro.noopbak', path);

final res = await NoopImporter.importFile(
bak, const Profile(), DerivationEngine());
expect(res.days, greaterThan(0));
expect(res.rows, 300);
}, timeout: const Timeout(Duration(minutes: 5)));

test('a long gap between blocks still derives the later day', () async {
// The prior-evening buffer used to be retained across ANY gap, handing the
// next day a Substrate spanning the whole thing. `calendarDays` walks that
Expand Down
Loading