{"record":{"id":"74389a5e46f1e98a","repo":"slackhq/nebula","slug":"encoded-subnets-should-be-in-pairs-an-odd-number","errorCode":null,"errorMessage":"encoded Subnets should be in pairs, an odd number was found","messagePattern":"encoded Subnets should be in pairs, an odd number was found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cert/cert_v1.go","lineNumber":421,"sourceCode":"\tif len(b) == 0 {\n\t\treturn nil, fmt.Errorf(\"nil byte array\")\n\t}\n\tvar rc RawNebulaCertificate\n\terr := proto.Unmarshal(b, &rc)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif rc.Details == nil {\n\t\treturn nil, fmt.Errorf(\"encoded Details was nil\")\n\t}\n\n\tif len(rc.Details.Ips)%2 != 0 {\n\t\treturn nil, fmt.Errorf(\"encoded IPs should be in pairs, an odd number was found\")\n\t}\n\n\tif len(rc.Details.Subnets)%2 != 0 {\n\t\treturn nil, fmt.Errorf(\"encoded Subnets should be in pairs, an odd number was found\")\n\t}\n\n\tnc := certificateV1{\n\t\tdetails: detailsV1{\n\t\t\tname:           rc.Details.Name,\n\t\t\tgroups:         make([]string, len(rc.Details.Groups)),\n\t\t\tnetworks:       make([]netip.Prefix, len(rc.Details.Ips)/2),\n\t\t\tunsafeNetworks: make([]netip.Prefix, len(rc.Details.Subnets)/2),\n\t\t\tnotBefore:      time.Unix(rc.Details.NotBefore, 0),\n\t\t\tnotAfter:       time.Unix(rc.Details.NotAfter, 0),\n\t\t\tpublicKey:      nil,\n\t\t\tisCA:           rc.Details.IsCA,\n\t\t\tcurve:          rc.Details.Curve,\n\t\t},\n\t\tsignature: make([]byte, len(rc.Signature)),\n\t}\n\n\tcopy(nc.signature, rc.Signature)","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/slackhq/nebula/blob/dd8f660c0ac37903ec4080ca4d3c861ba9342ceb/cert/cert_v1.go#L403-L439","documentation":"Like IPs, Subnets (unsafe_routes) in a v1 certificate are stored as (network, mask) uint32 pairs. An odd number of entries means a pair is incomplete, so the unmarshaler rejects the certificate instead of producing mis-paired subnets.","triggerScenarios":"unmarshalCertificateV1 receives a certificate whose rc.Details.Subnets has odd length — an unsafe_route written with a network but no mask, a dropped element, or corruption.","commonSituations":"Custom automation editing Subnets for unsafe_routes; a marshaling bug in generated tooling; truncated certificate data; hand-built test certificates.","solutions":["Make every subnet a network,mask pair (even-length Subnets array) before marshaling","Re-issue or regenerate the certificate using the library's marshaling functions","Fix the tooling/script that mutates the Subnets array","Validate with a quick len check on Subnets when constructing RawNebulaCertificate"],"exampleFix":"// before\nrc.Details.Subnets = []uint32{subnetToUint32(sub)} // odd length\n// after\nrc.Details.Subnets = []uint32{subnetToUint32(sub), maskToUint32(mask)}","handlingStrategy":"validation","validationCode":"func subnetsArePaired(subnets []uint32) bool { return len(subnets)%2 == 0 }\nif !subnetsArePaired(rc.Details.Subnets) {\n    return fmt.Errorf(\"Subnets must be (network,mask) pairs before marshaling\")\n}\nb, err := proto.Marshal(rc)","typeGuard":"func validSubnetPairCount(n int) bool { return n >= 0 && n%2 == 0 }","tryCatchPattern":"c, err := unmarshalCertificateV1(b, nil)\nif err != nil {\n    if strings.Contains(err.Error(), \"Subnets should be in pairs\") {\n        return nil, fmt.Errorf(\"corrupt certificate: odd Subnets length; regenerate cert\")\n    }\n    return nil, err\n}","preventionTips":["Write unsafe_routes via pairing helpers (network+mask always together)","Round-trip test certificates that manipulate Subnets","Reject odd-length Subnets arrays at build time in automation tooling","Regenerate certificates rather than editing raw protobuf fields"],"tags":["certificate","protobuf","subnets","validation"],"backgroundTag":"malformed-certificate","analyzedSha":"dd8f660c0ac37903ec4080ca4d3c861ba9342ceb","analyzedAt":"2026-09-03T11:13:55.444Z","contentChangedAt":"2026-09-03T11:13:55.444Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}