{"record":{"id":"5620b148aadee65e","repo":"golang/go","slug":"overflowing-coordinate-5620b1","errorCode":null,"errorMessage":"overflowing coordinate","messagePattern":"overflowing coordinate","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/crypto/elliptic/nistec.go","lineNumber":146,"sourceCode":"\tif x.Sign() == 0 && y.Sign() == 0 {\n\t\treturn false\n\t}\n\t_, err := curve.pointFromAffine(x, y)\n\treturn err == nil\n}\n\nfunc (curve *nistCurve[Point]) pointFromAffine(x, y *big.Int) (p Point, err error) {\n\t// (0, 0) is by convention the point at infinity, which can't be represented\n\t// in affine coordinates. See Issue 37294.\n\tif x.Sign() == 0 && y.Sign() == 0 {\n\t\treturn curve.newPoint(), nil\n\t}\n\t// Reject values that would not get correctly encoded.\n\tif x.Sign() < 0 || y.Sign() < 0 {\n\t\treturn p, errors.New(\"negative coordinate\")\n\t}\n\tif x.BitLen() > curve.params.BitSize || y.BitLen() > curve.params.BitSize {\n\t\treturn p, errors.New(\"overflowing coordinate\")\n\t}\n\t// Encode the coordinates and let SetBytes reject invalid points.\n\tbyteLen := (curve.params.BitSize + 7) / 8\n\tbuf := make([]byte, 1+2*byteLen)\n\tbuf[0] = 4 // uncompressed point\n\tx.FillBytes(buf[1 : 1+byteLen])\n\ty.FillBytes(buf[1+byteLen : 1+2*byteLen])\n\treturn curve.newPoint().SetBytes(buf)\n}\n\nfunc (curve *nistCurve[Point]) pointToAffine(p Point) (x, y *big.Int) {\n\tout := p.Bytes()\n\tif len(out) == 1 && out[0] == 0 {\n\t\t// This is the encoding of the point at infinity, which the affine\n\t\t// coordinates API represents as (0, 0) by convention.\n\t\treturn new(big.Int), new(big.Int)\n\t}\n\tbyteLen := (curve.params.BitSize + 7) / 8","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/crypto/elliptic/nistec.go#L128-L164","documentation":"Thrown by nistCurve.pointFromAffine (nistec.go:146) when a coordinate's bit-length exceeds curve.params.BitSize. Guards the fixed-width FillBytes buffer against overflow. Sibling of ecdsa error 242 at the elliptic-curve layer.","triggerScenarios":"Reached via elliptic curve operations when x.BitLen() > BitSize || y.BitLen() > BitSize — e.g. passing a P-384 coordinate to a P-256 nistCurve, or an unreduced value larger than the field.","commonSituations":"Curve mismatch between the point and the nistCurve object; coordinates derived from a hash without masking; deserialization that assigned the wrong curve.","solutions":["Match the point's coordinates to the correct curve (BitSize).","Reduce coordinates modulo the field prime before use.","Parse points via elliptic.UnmarshalCompressed/Unmarshal which validates against the curve."],"exampleFix":"// before\n// p384X assigned to a P256 curve object -> x.BitLen() > 256\n_, _ = p256.ScalarMult(p384X, p384Y, k) // -> error 254\n\n// after\n_, _ = p384.ScalarMult(p384X, p384Y, k)","handlingStrategy":"validation","validationCode":"bs := curve.Params().BitSize\nif x.BitLen() > bs || y.BitLen() > bs {\n    return fmt.Errorf(\"coordinate overflows %d-bit curve\", bs)\n}","typeGuard":"func coordsFitBitSize(curve elliptic.Curve, x, y *big.Int) bool {\n    bs := curve.Params().BitSize\n    return x.BitLen() <= bs && y.BitLen() <= bs\n}","tryCatchPattern":null,"preventionTips":["Match coordinates to the correct curve's BitSize.","Reduce coordinates modulo the field prime before use.","Parse points via elliptic.Unmarshal/UnmarshalCompressed which validate size."],"tags":["go","crypto","elliptic","validation"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}