{"record":{"id":"b21429a95a13ffb1","repo":"siyuan-note/siyuan","slug":"bazaar-downloads-overflow-s","errorCode":null,"errorMessage":"bazaar downloads overflow: %s","messagePattern":"bazaar downloads overflow: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/bazaar/index.go","lineNumber":268,"sourceCode":"\tif !hasMeta || 2 == ret.meta.Schema || bazaarIndexSchema < ret.meta.Schema {\n\t\tfor rawRepo, rawStats := range raw {\n\t\t\tif \"meta\" == rawRepo || \"packages\" == rawRepo {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\trepo, valid := normalizeLegacyBazaarRepo(rawRepo)\n\t\t\tif !valid {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid bazaar repository: %s\", rawRepo)\n\t\t\t}\n\t\t\tstats := &bazaarStats{}\n\t\t\tif err = json.Unmarshal(rawStats, stats); nil != err {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tif 0 > stats.Downloads {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid bazaar downloads: %s\", rawRepo)\n\t\t\t}\n\t\t\tif current := ret.legacyStats[repo]; nil != current {\n\t\t\t\tif stats.Downloads > int(^uint(0)>>1)-current.Downloads {\n\t\t\t\t\treturn nil, fmt.Errorf(\"bazaar downloads overflow: %s\", repo)\n\t\t\t\t}\n\t\t\t\tcurrent.Downloads += stats.Downloads\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tret.legacyStats[repo] = stats\n\t\t}\n\t}\n\treturn\n}\n\nfunc normalizeLegacyBazaarRepo(repo string) (string, bool) {\n\tconst githubPrefix = \"https://github.com/\"\n\tif strings.HasPrefix(repo, githubPrefix) {\n\t\trepo = strings.TrimPrefix(repo, githubPrefix)\n\t}\n\tif !isValidBazaarRepo(repo) {\n\t\treturn \"\", false\n\t}","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/bazaar/index.go#L250-L286","documentation":"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.","triggerScenarios":"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.","commonSituations":"A compromised or malformed upstream bazaar index, a proxy returning tampered index data, or unit-test fixtures with pathological download counters.","solutions":["Check the bazaar index JSON for duplicated repo entries with astronomically large download counts and fix the upstream data","Clear caches of the marketplace index and re-fetch from the official endpoint (verify no proxy is rewriting responses)","If testing, adjust the fixture so accumulated downloads fit within the platform int range"],"exampleFix":"// before: index JSON with repo \"foo/bar\" listed twice, downloads 9223372036854775807 and 1\n// after: correct the upstream index so total downloads <= MaxInt, or fix the duplicate legacy entry","handlingStrategy":"validation","validationCode":"const MaxInt = int(^uint(0) >> 1)\nif downloads < 0 || (legacy != nil && downloads > MaxInt-legacy.Downloads) {\n    return fmt.Errorf(\"bazaar downloads overflow: %s\", repo)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Sanitize upstream index numbers (reject negatives and values near MaxInt) before aggregating","Treat the marketplace index as untrusted input; validate before caching","Add fuzz/unit fixtures with extreme counters to index parsers"],"tags":["go","bazaar","integer-overflow","index-parsing"],"backgroundTag":"value-out-of-range","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}