{"record":{"id":"1e958828c0c77fe3","repo":"lionsoul2014/ip2region","slug":"invalid-version-d","errorCode":null,"errorMessage":"invalid version: %d","messagePattern":"invalid version: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"binding/golang/xdb/util.go","lineNumber":158,"sourceCode":"// The future features of the xdb impl may cause the current searcher not able to work properly.\n//\n// @Note: You Just need to check this ONCE when the service starts\n// Or use another process (eg, A command) to check once Just to confirm the suitability.\nfunc Verify(handle *os.File) error {\n\theader, err := LoadHeader(handle)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"loading header: %w\", err)\n\t}\n\n\t// get the runtime ptr bytes\n\truntimePtrBytes := 0\n\tswitch header.Version {\n\tcase Structure20:\n\t\truntimePtrBytes = 4\n\tcase Structure30:\n\t\truntimePtrBytes = header.RuntimePtrBytes\n\tdefault:\n\t\treturn fmt.Errorf(\"invalid version: %d\", header.Version)\n\t}\n\n\t// 1, confirm the xdb file size.\n\t// to sure that the MaxFilePointer does no overflow\n\tstat, err := handle.Stat()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"file stat: %w\", err)\n\t}\n\n\tmaxFilePtr := (int64(1) << (runtimePtrBytes * 8)) - 1\n\tif stat.Size() > maxFilePtr {\n\t\treturn fmt.Errorf(\"xdb file exceeds the maximum supported bytes: %d\", maxFilePtr)\n\t}\n\n\treturn nil\n}\n\n// VerifyFromFile check Verify for details","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/lionsoul2014/ip2region/blob/c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1/binding/golang/xdb/util.go#L140-L176","documentation":"Verify reads the header's Version field and only supports Structure20 (v2) and Structure30 (v3); any other version value fails with \"invalid version\". This guards against searching xdb files written by incompatible writer versions.","triggerScenarios":"Opening an xdb produced by a newer/older writer whose header version is not 2 or 3; a corrupted header where the version byte is garbage (often surfacing here after a partial header parse); mixing binding versions where the Go binding predates Structure30.","commonSituations":"Upgrading the data file to the v3 format while the application pins an old ip2region Go binding; hand-merged or edited xdb files; corrupted downloads where the header bytes are wrong.","solutions":["Upgrade the xdb Go binding to a version that supports Structure30 (v3) files","Regenerate or download the data file in the format matching your binding version","Check header.Version against xdb.Structure20/Structure30 before calling Verify","Re-download the file if the version value looks corrupted (e.g. huge or 0)"],"exampleFix":"// before\n// old binding: only Structure20\ndb, _ := xdb.LoadHeaderFromFile(\"v3.xdb\")\nerr := xdb.Verify(f) // invalid version: 3\n// after\n// go get -u github.com/lionsoul2014/ip2region/binding/golang\nheader, _ := xdb.LoadHeaderFromFile(\"v3.xdb\")\nfmt.Println(header.Version) // Structure30\nerr = xdb.VerifyFromFile(\"v3.xdb\")","handlingStrategy":"validation","validationCode":"header, err := xdb.LoadHeaderFromFile(\"ip2region.xdb\")\nif err != nil { return err }\nif header.Version != xdb.Structure20 && header.Version != xdb.Structure30 {\n    return fmt.Errorf(\"unsupported xdb version %d; regenerate the data file\", header.Version)\n}","typeGuard":"func supportedVersion(v int) bool {\n    return v == xdb.Structure20 || v == xdb.Structure30\n}","tryCatchPattern":"if err := xdb.VerifyFromFile(dbPath); err != nil {\n    if strings.Contains(err.Error(), \"invalid version\") {\n        return fmt.Errorf(\"re-download or regenerate %s in a supported format: %w\", dbPath, err)\n    }\n    return err\n}","preventionTips":["Pin the binding version and data-file format together in deployment","Check header.Version after LoadHeader before searching","Regenerate the xdb with the matching maker version when upgrading","Treat a nonsense version value as corruption and re-download"],"tags":["go","version-mismatch","file-format"],"backgroundTag":"xdb-version-unsupported","analyzedSha":"c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1","analyzedAt":"2026-09-02T16:58:39.988Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}