Skip to content

Commit d456039

Browse files
authored
[scanner] fix: resolve gosec security findings in kb/rag (#19280)
Signed-off-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9c99cb1 commit d456039

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

pkg/kb/rag/embedder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ func Quantize(v []float32) []uint64 {
6262
code := make([]uint64, (len(v)+63)/64)
6363
for i, x := range v {
6464
if x >= 0 {
65-
code[i/64] |= 1 << uint(i%64)
65+
// Safe conversion: i%64 is always in [0,63], well within uint range.
66+
code[i/64] |= 1 << uint(i%64) // #nosec G115
6667
}
6768
}
6869
return code

pkg/kb/rag/hashembedder.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ func (e *HashEmbedder) addFeature(vec []float32, feature string, weight float64)
100100
h := fnv.New64a()
101101
_, _ = h.Write([]byte(feature))
102102
sum := h.Sum64()
103-
idx := int(sum % uint64(e.dim))
103+
// Safe conversion: sum % uint64(e.dim) is always < e.dim (typically 512),
104+
// well within int range even on 32-bit systems.
105+
idx := int(sum % uint64(e.dim)) // #nosec G115
104106
sign := float32(1)
105107
if sum&(1<<63) != 0 {
106108
sign = -1

0 commit comments

Comments
 (0)