Skip to content

Commit 599993b

Browse files
committed
fix(traces): reject a float time whose nanosecond value overflows
A finite float like 1e308 becomes infinite once scaled to nanoseconds, so round() raised instead of the value falling back to the derived time.
1 parent f1bc1c8 commit 599993b

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

posthog/test/tracing/test_sanitize.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def test_converts_float_seconds(self):
5050
"1700000000",
5151
float("nan"),
5252
float("inf"),
53+
1e308,
5354
-1,
5455
MAX_TIMESTAMP_NS // 10**9 + 1,
5556
datetime(1960, 1, 1, tzinfo=timezone.utc),

posthog/tracing/_sanitize.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ def to_epoch_ns(value: Any) -> Optional[int]:
7676
elif isinstance(value, int):
7777
ns = value * 10**9
7878
elif isinstance(value, float):
79-
if not math.isfinite(value):
79+
scaled = value * 1e9
80+
if not math.isfinite(scaled):
8081
return None
81-
ns = int(round(value * 1e9))
82+
ns = int(round(scaled))
8283
else:
8384
return None
8485
if ns < MIN_TIMESTAMP_NS or ns > MAX_TIMESTAMP_NS:

0 commit comments

Comments
 (0)