fix: comprehensive bug audit — 15 critical/high/medium fixes
Critical fixes: - B-Tree splitChild: fixed out-of-bounds on child.children.len (mid+1..len → mid+1..<len) - Wire protocol: all deserializeValue cases now properly assign to result - Wire protocol: fkBool/fkInt8 now increment pos after reading - MVCC: write-write conflict now detected for completed transactions - MVCC: commit only marks visible versions as deleted (not concurrent uncommitted) - Lexer: buffer overrun on backslash escape at end of input — added bounds check - Bulgarian/Russian stemmers: fixed UTF-8 byte offsets for Cyrillic suffixes (2 bytes per char) High fixes: - WebSocket: added missing std/tables import - Raft: added randomize() call for election timeouts - MemTable.get: binary search O(log n) instead of linear scan O(n) Medium fixes: - Zerocopy: string length now written as 4-byte int32 (was single byte) - Raft appendEntries: guard against nextIdx underflow - Columnar: null tracking with nulls seq on ColumnPtr - Removed dead code in lexer readIdent (redundant true/false checks) - Updated Bulgarian stemming test to match corrected byte offsets All 214 tests pass across 48 suites with 0 failures.
This commit is contained in:
@@ -48,7 +48,7 @@ proc splitChild[K, V](parent: BTreeNode[K, V], index: int, order: int) =
|
||||
newNode.values.add(child.values[j])
|
||||
|
||||
if not child.isLeaf:
|
||||
for j in mid+1..child.children.len:
|
||||
for j in mid+1..<child.children.len:
|
||||
newNode.children.add(child.children[j])
|
||||
child.children.setLen(mid + 1)
|
||||
|
||||
|
||||
@@ -62,9 +62,20 @@ proc put*(mt: var MemTable, key: string, value: seq[byte], timestamp: uint64, de
|
||||
return true
|
||||
|
||||
proc get*(mt: MemTable, key: string): (bool, Entry) =
|
||||
for entry in mt.entries:
|
||||
if entry.key == key:
|
||||
return (true, entry)
|
||||
if mt.entries.len == 0:
|
||||
return (false, Entry())
|
||||
# Binary search since entries are kept sorted by key
|
||||
var lo = 0
|
||||
var hi = mt.entries.len - 1
|
||||
while lo <= hi:
|
||||
let mid = (lo + hi) div 2
|
||||
let cmp = cmp(mt.entries[mid].key, key)
|
||||
if cmp == 0:
|
||||
return (true, mt.entries[mid])
|
||||
elif cmp < 0:
|
||||
lo = mid + 1
|
||||
else:
|
||||
hi = mid - 1
|
||||
return (false, Entry())
|
||||
|
||||
proc scan*(mt: MemTable, startKey, endKey: string): seq[Entry] =
|
||||
|
||||
Reference in New Issue
Block a user