Harden sondib deleted-track guard

This commit is contained in:
yato committed 2026-11-29 15:59:19 +03:00
1 parent 1ac16fa382
commit b39bbd969c
2 files changed
+11 -4

No files matched your search

Binary file not shown.
+11 -4
View File
@@ -2,8 +2,8 @@
"""Apply the deleted-track guard to the bundled sondibd binary.
The repository ships the service as a release binary. This patch reuses an
alignment NOP sled immediately before ``st_find_sid`` and makes a matching SID
return no result when the track's deleted byte (offset 0x21d) is set.
alignment NOP sled immediately before ``st_find_sid`` and skips a matching
track when its deleted byte (offset 0x21d) is set.
"""
from __future__ import annotations
@@ -37,14 +37,21 @@ def patch(path: Path) -> None:
branch = bytes(data[match_offset:match_offset + len(OLD_BRANCH)])
if branch == bytes.fromhex("74 ca"):
# Upgrade the first revision: returning NULL immediately made callers
# that probe an old SID take a slow error path. Skipping the deleted
# record preserves the original search contract and is safe if a SID
# was ever duplicated in the in-memory table.
if data[guard_offset + 7:guard_offset + 9] == bytes.fromhex("75 39"):
data[guard_offset + 7:guard_offset + 9] = bytes.fromhex("75 2d")
path.write_bytes(data)
return
if branch != OLD_BRANCH or guard != OLD_GUARD:
raise SystemExit(f"unexpected sondibd bytes in {path}")
# je 0x404120; then reject track+0x21d when it is non-zero.
# je 0x404120; then skip track+0x21d when it is non-zero.
guard_code = bytes.fromhex(
"80 b9 1d 02 00 00 00 " # cmp byte ptr [rcx+0x21d], 0
"75 39 " # jne 0x404162 (the existing null return)
"75 2d " # jne 0x404156 (continue the search)
"48 89 c8 c3" # mov rax, rcx; ret
)
data[guard_offset:guard_offset + GUARD_SIZE] = guard_code.ljust(GUARD_SIZE, b"\x90")