fix(session): reject non-integer consolidated offsets

maintainer edit: corrupt session metadata can contain JSON strings, nulls, floats, or booleans. Reset non-integer offsets before range checks so recovery keeps valid messages visible instead of falling back to an empty session.
This commit is contained in:
chengyongru
2026-06-03 15:01:29 +08:00
committed by Xubin Ren
parent 0307ee6b73
commit 13178f3eaa
2 changed files with 48 additions and 3 deletions
+5 -1
View File
@@ -101,7 +101,11 @@ class Session:
def __post_init__(self) -> None:
# An out-of-range offset (corrupt metadata) would hide all history; reset it.
if not 0 <= self.last_consolidated <= len(self.messages):
if (
isinstance(self.last_consolidated, bool)
or not isinstance(self.last_consolidated, int)
or not 0 <= self.last_consolidated <= len(self.messages)
):
self.last_consolidated = 0
@staticmethod