{"record":{"id":"ba304a4e4b89903d","repo":"lionsoul2014/ip2region","slug":"xdb-file-exceeds-the-maximum-supported-bytes-d","errorCode":null,"errorMessage":"xdb file exceeds the maximum supported bytes: %d","messagePattern":"xdb file exceeds the maximum supported bytes: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"binding/golang/xdb/util.go","lineNumber":170,"sourceCode":"\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\nfunc VerifyFromFile(dbFile string) error {\n\thandle, err := os.OpenFile(dbFile, os.O_RDONLY, 0600)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"open xdb file `%s`: %w\", dbFile, err)\n\t}\n\tdefer handle.Close()\n\n\treturn Verify(handle)\n}\n\n// LoadHeader load the header info from the specified handle\nfunc LoadHeader(handle io.ReadSeeker) (*Header, error) {","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/lionsoul2014/ip2region/blob/c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1/binding/golang/xdb/util.go#L152-L188","documentation":"Verify enforces that the xdb file size does not exceed the maximum addressable by the runtime pointer width: 2^(ptrBytes*8)-1 (4 GiB - 1 for 4-byte pointers, larger for v3's wider pointers). A larger file cannot be indexed with the given pointer size, so Verify rejects it.","triggerScenarios":"Verifying an extremely large v2 (Structure20, fixed 4-byte pointers) xdb exceeding ~4 GiB; a v3 file whose header.RuntimePtrBytes is too small for the actual file size; corrupted header reporting a small pointer width.","commonSituations":"Building oversized custom xdb data sets with the v2 maker; mixing a v3 data file with a header claiming v2 pointer width; concatenated or duplicated files that ballooned past the limit.","solutions":["Use the v3 (Structure30) format with larger RuntimePtrBytes for data files over 4 GiB","Split the data into multiple xdb files (e.g. by region) each within the pointer limit","Regenerate the file with the current maker so header.RuntimePtrBytes matches the size","If the size looks bogus, verify file integrity — a corrupted header can shrink maxFilePtr"],"exampleFix":"// before\n// v2 file > 4GiB\nerr := xdb.Verify(f) // xdb file exceeds the maximum supported bytes: 4294967295\n// after\n// generate with v3 maker\n// ./xdb_maker gen --version=3 region.txt ip.v3.xdb\nerr := xdb.VerifyFromFile(\"ip.v3.xdb\") // ok (RuntimePtrBytes=8)","handlingStrategy":"validation","validationCode":"header, err := xdb.LoadHeaderFromFile(dbPath)\nif err != nil { return err }\nstat, err := os.Stat(dbPath)\nif err != nil { return err }\nptrBytes := 4\nif header.Version == xdb.Structure30 { ptrBytes = int(header.RuntimePtrBytes) }\nmaxSize := int64(1)<<(ptrBytes*8) - 1\nif stat.Size() > maxSize {\n    return fmt.Errorf(\"xdb %d bytes exceeds %d-byte limit for %d-byte pointers\", stat.Size(), maxSize, ptrBytes)\n}","typeGuard":null,"tryCatchPattern":"if err := xdb.VerifyFromFile(dbPath); err != nil {\n    if strings.Contains(err.Error(), \"exceeds the maximum supported bytes\") {\n        return fmt.Errorf(\"use v3 format or split the data: %w\", err)\n    }\n    return err\n}","preventionTips":["Use the v3 format with larger RuntimePtrBytes for very large datasets","Split oversized datasets into multiple xdb files within the size limit","Check the file size against the pointer-width limit at startup via Verify","Re-verify integrity if a previously valid file suddenly reports oversize"],"tags":["go","file-size","limit-exceeded","version-mismatch"],"backgroundTag":"xdb-file-too-large","analyzedSha":"c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1","analyzedAt":"2026-09-02T16:58:39.988Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}