mirror of
https://github.com/ollama/ollama
synced 2026-04-23 08:45:14 +00:00
fix: validate input size in parseSafetensors to prevent integer overflow
This commit is contained in:
parent
4b34930a31
commit
e565970a20
|
|
@ -36,6 +36,11 @@ func parseSafetensors(fsys fs.FS, replacer *strings.Replacer, ps ...string) ([]T
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Validate the value of n
|
||||
if n <= 0 || n > 1<<30 { // Example: Limit n to 1GB for safety
|
||||
return nil, fmt.Errorf("invalid or excessive size for safetensors file: %d", n)
|
||||
}
|
||||
|
||||
b := bytes.NewBuffer(make([]byte, 0, n))
|
||||
if _, err = io.CopyN(b, f, n); err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Reference in a new issue