{"record":{"id":"21bf7bd7cfbc0d91","repo":"vitessio/vitess","slug":"cannot-parse-int64-from-q-w","errorCode":null,"errorMessage":"cannot parse int64 from %q: %w","messagePattern":"cannot parse int64 from %q: %w","errorType":"validation","errorClass":"ErrOverflow","httpStatus":null,"severity":"warning","filePath":"go/mysql/fastparse/fastparse.go","lineNumber":195,"sourceCode":"\t\tdefault:\n\t\t\tbreak next\n\t\t}\n\n\t\tif b >= byte(base) {\n\t\t\tbreak next\n\t\t}\n\n\t\tvar cutoff uint64\n\t\tswitch base {\n\t\tcase 10:\n\t\t\tcutoff = math.MaxInt64/10 + 1\n\t\tcase 16:\n\t\t\tcutoff = math.MaxInt64/16 + 1\n\t\tdefault:\n\t\t\tcutoff = math.MaxInt64/uint64(base) + 1\n\t\t}\n\t\tif !minus && d >= cutoff {\n\t\t\treturn math.MaxInt64, fmt.Errorf(\"cannot parse int64 from %q: %w\", s, ErrOverflow)\n\t\t}\n\n\t\tif minus && d > cutoff {\n\t\t\treturn math.MinInt64, fmt.Errorf(\"cannot parse int64 from %q: %w\", s, ErrOverflow)\n\t\t}\n\n\t\td = d*uint64(base) + uint64(b)\n\t\ti++\n\t}\n\n\tv := int64(d)\n\tif d > math.MaxInt64 && !minus {\n\t\treturn math.MaxInt64, fmt.Errorf(\"cannot parse int64 from %q: %w\", s, ErrOverflow)\n\t} else if d > math.MaxInt64+1 && minus {\n\t\treturn math.MinInt64, fmt.Errorf(\"cannot parse int64 from %q: %w\", s, ErrOverflow)\n\t}\n\n\tif minus {","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/mysql/fastparse/fastparse.go#L177-L213","documentation":"ParseInt64 reports overflow (wrapping ErrOverflow) when a positive value's accumulated digits reach or exceed the cutoff MaxInt64/base+1 during the digit loop, meaning the remaining digits cannot possibly fit in an int64. It returns math.MaxInt64 as the best-effort value.","triggerScenarios":"Calling fastparse.ParseInt64 with a positive decimal (or any-base) string whose magnitude exceeds math.MaxInt64, e.g. ParseInt64(\"9223372036854775808\", 10) or ParseInt64(\"FFFFFFFFFFFFFFFF\", 16).","commonSituations":"Parsing user-supplied SQL integer literals that exceed the signed 64-bit range, importing data meant for BIGINT UNSIGNED into an int64 field, or id/sequence values from another system that used unsigned 64-bit IDs.","solutions":["Use errors.Is(err, fastparse.ErrOverflow) to distinguish overflow from syntax errors and handle it explicitly (clamp, reject, or switch to uint64 parsing).","Parse with fastparse.ParseUint64 instead if the value legitimately fits in the unsigned range.","Clamp to math.MaxInt64 (the returned value already does this) and log a warning if clamping is acceptable."],"exampleFix":"// before\nv, err := fastparse.ParseInt64(s, 10)\n// after\nv, err := fastparse.ParseInt64(s, 10)\nif errors.Is(err, fastparse.ErrOverflow) {\n    return vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, \"value %q exceeds int64 range\", s)\n}","handlingStrategy":"validation","validationCode":"func fitsInt64(s string) bool {\n    v, err := fastparse.ParseInt64(strings.TrimSpace(s), 10)\n    return err == nil || !errors.Is(err, fastparse.ErrOverflow)\n    _ = v\n}","typeGuard":null,"tryCatchPattern":"v, err := fastparse.ParseInt64(s, 10)\nif errors.Is(err, fastparse.ErrOverflow) {\n    return vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, \"value %q overflows int64\", s)\n}","preventionTips":["Use ParseUint64 when values may legitimately exceed MaxInt64.","Range-check oversized literals with math/big before coercion.","Distinguish overflow via errors.Is(err, fastparse.ErrOverflow), never string matching."],"tags":["parsing","int64","overflow"],"backgroundTag":"integer-overflow","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}