Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Ollama Ollama VerifyBlob

From Leeroopedia
Knowledge Sources
Domains Security, Storage
Last Updated 2026-02-14 00:00 GMT

Overview

Concrete tool for verifying SHA-256 integrity of stored model blobs provided by the server and manifest packages.

Description

verifyBlob reads a blob file by digest, computes its SHA-256 hash, and compares it against the expected digest. Returns errDigestMismatch if the blob is corrupted.

GetSHA256Digest computes the SHA-256 digest of arbitrary content from a reader, returning the digest string and byte count.

Layer.Open provides read access to a blob's content by resolving its digest to a filesystem path and opening the file.

Usage

Called during model pull (after download), model loading (integrity check), and blob upload preparation.

Code Reference

Source Location

  • Repository: ollama
  • File: server/images.go (verifyBlob, GetSHA256Digest), manifest/layer.go (Layer.Open)
  • Lines: images.go:L983-1001 (verifyBlob), images.go:L831-839 (GetSHA256Digest), layer.go:L96-108 (Layer.Open)

Signature

func verifyBlob(digest string) error
func GetSHA256Digest(r io.Reader) (string, int64)
func (l *Layer) Open() (io.ReadSeekCloser, error)

Import

import "github.com/ollama/ollama/server"
import "github.com/ollama/ollama/manifest"

I/O Contract

Inputs (verifyBlob)

Name Type Required Description
digest string Yes Expected SHA-256 digest (e.g., "sha256:abc123...")

Outputs (verifyBlob)

Name Type Description
error error nil if digest matches, errDigestMismatch if corrupted, other error if file unreadable

Inputs (GetSHA256Digest)

Name Type Required Description
r io.Reader Yes Content to hash

Outputs (GetSHA256Digest)

Name Type Description
string string Computed digest in format "sha256:<hex>"
int64 int64 Number of bytes read

Usage Examples

Verifying a Downloaded Blob

import "github.com/ollama/ollama/server"

// After downloading a blob
err := verifyBlob("sha256:abc123def456...")
if err != nil {
    // Blob is corrupted, re-download
    log.Println("Blob integrity check failed:", err)
}

Computing a Digest

import "github.com/ollama/ollama/server"

f, _ := os.Open("model.gguf")
defer f.Close()
digest, size := server.GetSHA256Digest(f)
fmt.Printf("Digest: %s, Size: %d bytes\n", digest, size)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment