siyuan-note/siyuan · error

bazaar downloads overflow

Error message

bazaar downloads overflow: %s

What it means

parseBazaarIndex aggregates download counts from the bazaar index's legacy `downloads` map into per-package stats. When summing a package's downloads would exceed the platform's maximum int value (int overflow on 64-bit: MaxInt64), it refuses to build a corrupt index and returns this error with the offending repo URL.

Solutions

  1. Check the bazaar index JSON for duplicated repo entries with astronomically large download counts and fix the upstream data
  2. Clear caches of the marketplace index and re-fetch from the official endpoint (verify no proxy is rewriting responses)
  3. If testing, adjust the fixture so accumulated downloads fit within the platform int range

Example fix

// before: index JSON with repo "foo/bar" listed twice, downloads 9223372036854775807 and 1
// after: correct the upstream index so total downloads <= MaxInt, or fix the duplicate legacy entry
Defensive patterns

Strategy: validation

Validate before calling

const MaxInt = int(^uint(0) >> 1)
if downloads < 0 || (legacy != nil && downloads > MaxInt-legacy.Downloads) {
    return fmt.Errorf("bazaar downloads overflow: %s", repo)
}

Prevention

When it happens

Trigger: Fetching/parsing a bazaar index JSON where the same repo key appears both in the current `packages`-style download stats and in the legacy `downloads` map, and their combined count exceeds MaxInt (i.e. the index data is malicious or corrupted). Tests invoke it directly with crafted index JSON.

Common situations: A compromised or malformed upstream bazaar index, a proxy returning tampered index data, or unit-test fixtures with pathological download counters.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/b21429a95a13ffb1. Report an issue: GitHub.

Appendix: source

Thrown at kernel/bazaar/index.go:268

	if !hasMeta || 2 == ret.meta.Schema || bazaarIndexSchema < ret.meta.Schema {
		for rawRepo, rawStats := range raw {
			if "meta" == rawRepo || "packages" == rawRepo {
				continue
			}
			repo, valid := normalizeLegacyBazaarRepo(rawRepo)
			if !valid {
				return nil, fmt.Errorf("invalid bazaar repository: %s", rawRepo)
			}
			stats := &bazaarStats{}
			if err = json.Unmarshal(rawStats, stats); nil != err {
				return nil, err
			}
			if 0 > stats.Downloads {
				return nil, fmt.Errorf("invalid bazaar downloads: %s", rawRepo)
			}
			if current := ret.legacyStats[repo]; nil != current {
				if stats.Downloads > int(^uint(0)>>1)-current.Downloads {
					return nil, fmt.Errorf("bazaar downloads overflow: %s", repo)
				}
				current.Downloads += stats.Downloads
				continue
			}
			ret.legacyStats[repo] = stats
		}
	}
	return
}

func normalizeLegacyBazaarRepo(repo string) (string, bool) {
	const githubPrefix = "https://github.com/"
	if strings.HasPrefix(repo, githubPrefix) {
		repo = strings.TrimPrefix(repo, githubPrefix)
	}
	if !isValidBazaarRepo(repo) {
		return "", false
	}

View on GitHub (pinned to 9f775e8a12)