Skip to content

Commit 8499f61

Browse files
committed
fix: extend digest verification to sha512 and set sandbox paths
Extend blob digest verification to cover sha512 in addition to sha256, closing a bypass where sha512-addressed blobs were stored without any integrity check. Set correct SandboxPath for Python backends (diffusers, mlx, vllm-metal) so the Darwin sandbox profile resolves UPDATEDLIBPATH to the sibling lib/ directory of the Python bin/ directory.
1 parent b48efb3 commit 8499f61

4 files changed

Lines changed: 16 additions & 7 deletions

File tree

pkg/distribution/internal/store/blobs.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package store
33
import (
44
"context"
55
"crypto/sha256"
6+
"crypto/sha512"
67
"encoding/hex"
78
"errors"
89
"fmt"
10+
"hash"
911
"io"
1012
"os"
1113
"path/filepath"
@@ -276,14 +278,20 @@ func (s *LocalStore) WriteBlobWithResume(diffID oci.Hash, r io.Reader, digestStr
276278
// We hash the whole file rather than the streamed bytes so that resumed
277279
// downloads (which append to an existing partial file) are verified
278280
// correctly over their entire contents.
279-
if diffID.Algorithm == "sha256" {
281+
var hasher hash.Hash
282+
switch diffID.Algorithm {
283+
case "sha256":
284+
hasher = sha256.New()
285+
case "sha512":
286+
hasher = sha512.New()
287+
}
288+
if hasher != nil {
280289
completedFile, openErr := os.Open(incompletePath)
281290
if openErr != nil {
282291
_ = os.Remove(incompletePath)
283292
return fmt.Errorf("open completed blob file for verification: %w", openErr)
284293
}
285294

286-
hasher := sha256.New()
287295
if _, copyErr := io.Copy(hasher, completedFile); copyErr != nil {
288296
completedFile.Close()
289297
_ = os.Remove(incompletePath)
@@ -294,8 +302,8 @@ func (s *LocalStore) WriteBlobWithResume(diffID oci.Hash, r io.Reader, digestStr
294302
computed := hex.EncodeToString(hasher.Sum(nil))
295303
if computed != diffID.Hex {
296304
_ = os.Remove(incompletePath)
297-
return fmt.Errorf("blob digest mismatch for %q: expected sha256:%s, got sha256:%s",
298-
diffID.String(), diffID.Hex, computed)
305+
return fmt.Errorf("blob digest mismatch for %q: expected %s:%s, got %s:%s",
306+
diffID.String(), diffID.Algorithm, diffID.Hex, diffID.Algorithm, computed)
299307
}
300308
}
301309

pkg/inference/backends/diffusers/diffusers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func (d *diffusers) Run(ctx context.Context, socket, model string, modelRef stri
255255
BackendName: "Diffusers",
256256
Socket: socket,
257257
BinaryPath: d.pythonPath,
258-
SandboxPath: "",
258+
SandboxPath: filepath.Dir(d.pythonPath),
259259
SandboxConfig: sandbox.ConfigurationPython,
260260
Args: args,
261261
Logger: d.log,

pkg/inference/backends/mlx/mlx.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"net/http"
88
"os/exec"
9+
"path/filepath"
910
"strings"
1011

1112
"github.com/docker/model-runner/pkg/inference"
@@ -140,7 +141,7 @@ func (m *mlx) Run(ctx context.Context, socket, model string, modelRef string, mo
140141
BackendName: "MLX",
141142
Socket: socket,
142143
BinaryPath: m.pythonPath,
143-
SandboxPath: "",
144+
SandboxPath: filepath.Dir(m.pythonPath),
144145
SandboxConfig: sandbox.ConfigurationPython,
145146
Args: args,
146147
Logger: m.log,

pkg/inference/backends/vllm/vllm_metal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func (v *vllmMetal) Run(ctx context.Context, socket, model string, modelRef stri
217217
BackendName: "vllm-metal",
218218
Socket: socket,
219219
BinaryPath: v.pythonPath,
220-
SandboxPath: v.installDir,
220+
SandboxPath: filepath.Join(v.installDir, "bin"),
221221
SandboxConfig: sandbox.ConfigurationPython,
222222
Args: args,
223223
Logger: v.log,

0 commit comments

Comments
 (0)