{"record":{"id":"13bed2a8a5840f23","repo":"valyala/fasthttp","slug":"value-exceeds-uint32-max-value","errorCode":null,"errorMessage":"value exceeds uint32 max value","messagePattern":"value exceeds uint32 max value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tcplisten/tcplisten.go","lineNumber":195,"sourceCode":"\t\t\t}\n\t\t\tsa6.ZoneId, err = safeIntToUint32(ifi.Index)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, -1, fmt.Errorf(\"unexpected convert net interface index int to uint32: %w\", err)\n\t\t\t}\n\t\t}\n\t\treturn &sa6, unix.AF_INET6, nil\n\tdefault:\n\t\treturn nil, -1, errors.New(\"only tcp, tcp4, or tcp6 is supported \" + network)\n\t}\n}\n\nfunc safeIntToUint32(i int) (uint32, error) {\n\tif i < 0 {\n\t\treturn 0, errors.New(\"value is negative, cannot convert to uint32\")\n\t}\n\tui := uint64(i)\n\tif ui > math.MaxUint32 {\n\t\treturn 0, errors.New(\"value exceeds uint32 max value\")\n\t}\n\treturn uint32(ui), nil\n}\n\nfunc safeIntToUintptr(i int) (uintptr, error) {\n\tif i < 0 {\n\t\treturn 0, errors.New(\"value is negative, cannot convert to uintptr\")\n\t}\n\treturn uintptr(i), nil\n}\n","sourceCodeStart":177,"sourceCodeEnd":206,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/tcplisten/tcplisten.go#L177-L206","documentation":"safeIntToUint32 also rejects values above math.MaxUint32 that would overflow a uint32. On 64-bit platforms an int can hold larger values, so the explicit check prevents truncation when the value is embedded in a 32-bit sockaddr field.","triggerScenarios":"getSockaddr receives an interface index (or other int parameter) exceeding 4294967295 and calls safeIntToUint32 while constructing the sockaddr for NewListener. Practically only possible on 64-bit systems with a corrupted/garbage index value.","commonSituations":"Garbage or byte-swapped value parsed from config or a packet read as interface index; unchecked cast of an unsigned 64-bit field into int before passing in.","solutions":["Validate the source of the index; it should come from net.Interfaces()/InterfaceByIndex, never parsed ad hoc","Range-check the value (0 <= v <= math.MaxUint32) before calling NewListener","Fix any byte-order/parsing bug producing the oversized value"],"exampleFix":"// before\nidx := int(rawUint64) // may exceed uint32\n// after\nif rawUint64 > math.MaxUint32 { return errors.New(\"interface index out of range\") }\nidx := int(rawUint64)","handlingStrategy":"validation","validationCode":"func validateIfaceIndexRange(idx int) error {\n  if idx < 0 || uint64(idx) > math.MaxUint32 {\n    return fmt.Errorf(\"interface index %d out of uint32 range\", idx)\n  }\n  return nil\n}","typeGuard":"func isUint32Safe(i int) bool { return i >= 0 && uint64(i) <= math.MaxUint32 }","tryCatchPattern":"ln, err := ctl.NewListener(network, addr)\nif err != nil {\n  if strings.Contains(err.Error(), \"value exceeds uint32 max value\") {\n    return fmt.Errorf(\"interface index %d overflows uint32: %w\", ifaceIdx, err)\n  }\n  return err\n}","preventionTips":["Obtain indices only from net.Interfaces() rather than parsing raw bytes","Range-check any 64-bit parsed value before narrowing to int/uint32","Fuzz or unit-test config parsers for out-of-range numerics","Beware byte-order mistakes when reading indices from binary formats"],"tags":["network","ipv6","integer-overflow","validation"],"backgroundTag":"int-overflow-uint32","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}