Changeset 0.22.0 (#93)

This commit is contained in:
2026-03-01 23:57:33 +00:00
parent 3423738286
commit 12e03cec8b
5 changed files with 385 additions and 3 deletions

View File

@@ -46,7 +46,15 @@ func (s *jsonScanner) Scan(src interface{}) error {
*s.dest = json.RawMessage("{}")
return nil
}
*s.dest = json.RawMessage(v)
// CRITICAL: copy the driver buffer. json.RawMessage(v) aliases the
// underlying []byte owned by database/sql. The driver may reuse that
// memory on the next rows.Scan() call, corrupting our data after the
// fact. This caused intermittent SafeJSON 500s on paginated list
// endpoints where row N's Settings pointed to row N+1's overwritten
// buffer. Fixed in v0.21.7.
cp := make([]byte, len(v))
copy(cp, v)
*s.dest = json.RawMessage(cp)
case string:
b := []byte(v)
if len(b) == 0 || !json.Valid(b) {