siyuan-note/siyuan · error

bazaar downloads overflow: %s

Error message

bazaar downloads overflow: %s

What it means

When the same repository appears under multiple (case/prefix-variant) keys in a legacy index, downloads are summed into one entry. parseBazaarIndex throws this guard when adding a new count would overflow int (the platform's max int), preventing wraparound.

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 8641553a1f)

Solutions

  1. Treat this as untrusted/tampered index data: re-fetch from the official bazaar stat server and verify contents
  2. If operating a mirror, sanity-limit downloads values to plausible ranges before serving
  3. Inspect the named repo's entries in the JSON and correct the inflated counts

Example fix

// before
{"u/r": {"downloads": 9223372036854775807}, "U/R": {"downloads": 5}}
// after
{"u/r": {"downloads": 9223372036854775802}}
Defensive patterns

Strategy: validation

Validate before calling

// normalize repo keys first and reject implausible totals
if stats.Downloads > 1_000_000_000 {
	return fmt.Errorf("implausible downloads for %s", repo)
}

Try / catch

snapshot, err := parseBazaarIndex(data)
if err != nil {
	if strings.HasPrefix(err.Error(), "bazaar downloads overflow:") {
		log.Errorf("suspected tampered index (int overflow); discard and refetch")
	}
	return err
}

Prevention

When it happens

Trigger: An index JSON lists the same repo under two normalized-equal keys whose combined downloads exceed int(^uint(0)>>1) (max int64 on 64-bit); the second occurrence's addition is checked and rejected.

Common situations: Essentially only adversarial or fabricated index data — a malicious or buggy mirror emitting astronomically large download counts to trigger overflow; real totals never reach max int64.

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@8641553a1f (2026-09-11). Data as JSON: /api/errors/b21429a95a13ffb1. Report an issue: GitHub.