diff --git a/bincio/extract/metrics.py b/bincio/extract/metrics.py index 216db4e..d5bb97a 100644 --- a/bincio/extract/metrics.py +++ b/bincio/extract/metrics.py @@ -131,6 +131,10 @@ def compute_mmp(pts: list[DataPoint], started_at: datetime) -> Optional[list[lis t_min = min(sparse) t_max = max(sparse) + # Guard against corrupted time data (e.g. absolute Unix timestamps stored as + # elapsed offsets, which can make t_max astronomically large and OOM the process). + if t_max - t_min > 7 * 24 * 3600: # > 1 week → corrupted stream + return None power_1hz: list[int] = [sparse.get(t, 0) for t in range(t_min, t_max + 1)] n = len(power_1hz) @@ -190,6 +194,10 @@ def compute_best_efforts( t_min = min(sparse_speed) t_max = max(sparse_speed) + # Guard against corrupted time data (e.g. absolute Unix timestamps stored as + # elapsed offsets, which can make t_max astronomically large and OOM the process). + if t_max - t_min > 7 * 24 * 3600: # > 1 week → corrupted stream + return None, None speed_1hz: list[float] = [sparse_speed.get(t, 0.0) for t in range(t_min, t_max + 1)] ele_1hz: list[Optional[float]] = [sparse_ele.get(t) for t in range(t_min, t_max + 1)]