larksuite/cli · error

invalid total size: %d

Error message

invalid total size: %d

What it means

The Content-Range total parsed successfully but was zero or negative, which is impossible for a real resource. The library rejects it because range math and completeness checks depend on a positive total size.

Source

Thrown at extension/download/download.go:705

	}
	bounds := strings.SplitN(parts[0], "-", 2)
	if len(bounds) != 2 || bounds[0] == "" || bounds[1] == "" {
		return contentRange{}, fmt.Errorf("unsupported content-range: %q", header)
	}
	start, err := strconv.ParseInt(bounds[0], 10, 64)
	if err != nil {
		return contentRange{}, fmt.Errorf("parse range start: %w", err)
	}
	end, err := strconv.ParseInt(bounds[1], 10, 64)
	if err != nil {
		return contentRange{}, fmt.Errorf("parse range end: %w", err)
	}
	total, err := strconv.ParseInt(parts[1], 10, 64)
	if err != nil {
		return contentRange{}, fmt.Errorf("parse total size: %w", err)
	}
	if total <= 0 {
		return contentRange{}, fmt.Errorf("invalid total size: %d", total)
	}
	if start < 0 || end < 0 {
		return contentRange{}, fmt.Errorf("invalid negative content range: %d-%d", start, end)
	}
	if start > end {
		return contentRange{}, fmt.Errorf("invalid content range: start %d is after end %d", start, end)
	}
	if end >= total {
		return contentRange{}, fmt.Errorf("invalid content range: end %d is outside total %d", end, total)
	}
	return contentRange{start: start, end: end, total: total}, nil
}

// strongETag returns a validator suitable for If-Range.
func strongETag(header http.Header) (string, bool) {
	values := header.Values("ETag")
	if len(values) != 1 {
		return "", false

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Verify the object actually exists and has a positive size on the storage backend.
  2. Fix the server's size reporting (Content-Length/Content-Range).
  3. Re-upload or recreate the object if its metadata is corrupt.
  4. Use a plain GET without Range for empty or dynamically sized resources.

Example fix

// before
// Content-Range: bytes 0-0/0
// after
// Content-Range: bytes 0-0/1
Defensive patterns

Strategy: validation

Validate before calling

func positiveTotal(h string) bool {
	_, spec, _ := strings.Cut(h, " ")
	_, total, _ := strings.Cut(spec, "/")
	n, err := strconv.ParseInt(total, 10, 64)
	return err == nil && n > 0
}

Try / catch

cr, err := parseContentRange(header)
if err != nil {
	// bogus total: fetch full body without Range
	return downloadFull(ctx, url)
}

Prevention

When it happens

Trigger: openPartial or openNext received e.g. 'bytes 0-0/0' or 'bytes 0-99/-1'.

Common situations: Empty/dynamically generated objects with bogus metadata; servers with uninitialized size fields; broken mock servers.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/67df838272695fe5. Report an issue: GitHub.