Validates gzip/tar archive declared sizes before extraction to prevent decompression-bomb attacks exceeding managed runtime disk limits for Ollama.
// Source: https://github.com/thibautrey/multivibe | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
package main
import (
"archive/tar"
"compress/gzip"
"context"
"errors"
"io"
"os"
)
// Validate the sum of declared regular-file sizes before native tar creates
// anything. This protects the disk reservation from a small compressed archive
// expanding beyond the managed-runtime limit. Paths are validated separately.
func validateManagedOllamaGzipSize(ctx context.Context, archive string) error {
f, err := os.Open(archive)
if err != nil {
return err
}
defer f.Close()
gz, err := gzip.NewReader(f)
if err != nil {
return err
}
defer gz.Close()
return validateManagedO
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key