fix(oplog): use json.Decoder to handle arbitrarily large JSONL lines

Replace bufio.Scanner with json.NewDecoder which has no fixed line
length limit. Fixes "token too long" crash when audit results produce
JSONL entries exceeding the 64KB scanner default.
This commit is contained in:
Willie
2026-02-25 19:39:28 +08:00
parent 07c2aa6938
commit 6d7ced4d76
+8 -12
View File
@@ -3,7 +3,6 @@
package oplog
import (
"bufio"
"encoding/json"
"os"
"path/filepath"
@@ -92,21 +91,18 @@ func Read(configPath, filename string, limit int) ([]Entry, error) {
defer f.Close()
var all []Entry
scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := scanner.Bytes()
if len(line) == 0 {
continue
}
dec := json.NewDecoder(f)
for dec.More() {
var e Entry
if err := json.Unmarshal(line, &e); err != nil {
continue // skip malformed lines
if err := dec.Decode(&e); err != nil {
// Skip malformed entries — advance past the bad line
if dec.More() {
continue
}
break
}
all = append(all, e)
}
if err := scanner.Err(); err != nil {
return nil, err
}
// Reverse to newest-first
for i, j := 0, len(all)-1; i < j; i, j = i+1, j-1 {