[PR #14709] cmd: prevent division by zero panic in createBlob progress #77095

Open
opened 2026-05-05 09:47:52 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/14709
Author: @alvinttang
Created: 3/8/2026
Status: 🔄 Open

Base: mainHead: fix/create-blob-division-by-zero


📝 Commits (1)

  • 0a6ccf8 cmd: prevent division by zero panic in createBlob progress

📊 Changes

1 file changed (+3 additions, -1 deletions)

View changed files

📝 cmd/cmd.go (+3 -1)

📄 Description

Summary

The createBlob function in cmd/cmd.go has a goroutine that computes upload progress percentage using:

int(100 * pw.n.Load() / fileSize)

When fileSize is 0 (empty file), this causes a runtime panic due to integer division by zero. While uploading empty files is uncommon, it can happen with placeholder files or edge cases in model creation pipelines.

This fix guards the division with a fileSize > 0 check, skipping the percentage update for zero-length files (the "100%" message is still shown on completion via the done channel).

Test plan

  • go build ./cmd/... compiles without errors
  • Manual test: create a blob from an empty file (previously panics, now shows spinner without percentage until complete)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/14709 **Author:** [@alvinttang](https://github.com/alvinttang) **Created:** 3/8/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/create-blob-division-by-zero` --- ### 📝 Commits (1) - [`0a6ccf8`](https://github.com/ollama/ollama/commit/0a6ccf89cf3ac9a095ec5fa0e06d0f835f16c044) cmd: prevent division by zero panic in createBlob progress ### 📊 Changes **1 file changed** (+3 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `cmd/cmd.go` (+3 -1) </details> ### 📄 Description ## Summary The `createBlob` function in `cmd/cmd.go` has a goroutine that computes upload progress percentage using: ```go int(100 * pw.n.Load() / fileSize) ``` When `fileSize` is 0 (empty file), this causes a **runtime panic** due to integer division by zero. While uploading empty files is uncommon, it can happen with placeholder files or edge cases in model creation pipelines. This fix guards the division with a `fileSize > 0` check, skipping the percentage update for zero-length files (the "100%" message is still shown on completion via the `done` channel). ## Test plan - [x] `go build ./cmd/...` compiles without errors - [ ] Manual test: create a blob from an empty file (previously panics, now shows spinner without percentage until complete) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-05 09:47:52 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#77095