Skip to content

gguf: store TensorInfo and KeyValue by value in lookup maps - #83

Merged
janpfeifer merged 1 commit into
mainfrom
fix-GHSA-372p-cjj6-v33v
Nov 16, 2026
Merged

janpfeifer merged 1 commit into
mainfrom
fix-GHSA-372p-cjj6-v33v

Conversation

@janpfeifer

Copy link
Copy Markdown
Contributor

Fixes https://github.com/gomlx/go-huggingface/security/advisories/GHSA-372p-cjj6-v33v

Summary

  • Changed File.tensorByName from map[string]*TensorInfo to map[string]TensorInfo and File.kvByKey from map[string]*KeyValue to map[string]KeyValue in models/gguf/gguf.go.
  • Previously, File.tensorByName stored pointers into File.TensorInfos before slices.SortFunc(file.TensorInfos, ...) reordered the slice by offset, causing GetTensorInfo to return mismatched entries whenever tensor infos in the GGUF header were not already sorted by offset.
  • Storing these small value types directly in the maps keeps lookups independent of slice ordering or future slice mutations/reallocations without changing any exported types or signatures.
  • Added TestTensorInfoLookupWithUnsortedOffsets regression test in models/gguf/gguf_test.go.

Testing

  • go test -v ./models/gguf/...
  • go test -short ./...

Previously, File.tensorByName stored pointers into File.TensorInfos before
slices.SortFunc reordered File.TensorInfos by offset, causing GetTensorInfo
to return mismatched TensorInfo entries whenever tensor infos were not
already sorted by offset.

Store TensorInfo and KeyValue by value in File.tensorByName and File.kvByKey
so lookups remain independent of slice ordering or reallocation.

Fixes https://github.com/gomlx/go-huggingface/security/advisories/GHSA-372p-cjj6-v33v
@janpfeifer
janpfeifer merged commit 3770881 into main Nov 16, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant