{"record":{"id":"0c0ac0bce4b29b44","repo":"crowdsecurity/crowdsec","slug":"unknown-ip-size-d-w-0c0ac0","errorCode":null,"errorMessage":"unknown ip size %d: %w","messagePattern":"unknown ip size (.+?): %w","errorType":"validation","errorClass":"InvalidFilter","httpStatus":null,"severity":"error","filePath":"pkg/database/decisionfilter.go","lineNumber":193,"sourceCode":"\t\t\t\t// decision.end_ip == query.end_ip\n\t\t\t\tdecision.EndIPEQ(rng.End.Addr),\n\t\t\t\t// decision.end_suffix <= query.end_suffix\n\t\t\t\tdecision.EndSuffixLTE(rng.End.Sfx),\n\t\t\t),\n\t\t),\n\t)), nil\n}\n\nfunc decisionIPFilter(decisions *ent.DecisionQuery, contains bool, rng csnet.Range) (*ent.DecisionQuery, error) {\n\tswitch rng.Size() {\n\tcase 4:\n\t\treturn decisionIPv4Filter(decisions, contains, rng)\n\tcase 16:\n\t\treturn decisionIPv6Filter(decisions, contains, rng)\n\tcase 0:\n\t\treturn decisions, nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unknown ip size %d: %w\", rng.Size(), InvalidFilter)\n\t}\n}\n\nfunc decisionPredicatesFromStr(s string, predicateFunc func(string) predicate.Decision) []predicate.Decision {\n\twords := strings.Split(s, \",\")\n\tpredicates := make([]predicate.Decision, len(words))\n\n\tfor i, word := range words {\n\t\tpredicates[i] = predicateFunc(word)\n\t}\n\n\treturn predicates\n}\n","sourceCodeStart":175,"sourceCodeEnd":207,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/decisionfilter.go#L175-L207","documentation":"decisionIPFilter only knows how to apply filters for 4-byte (IPv4), 16-byte (IPv6) or empty (0) ranges; any other netip.Addr byte-length raises this error wrapped with the InvalidFilter sentinel. It signals an impossible/unsupported range size from malformed address data.","triggerScenarios":"Calling applyDecisionFilter, ExpireDecisionsWithFilter, CountDecisionsByValue or GetActiveDecisionsTimeLeftByValue with a csnet.Range whose underlying address has a size other than 0/4/16 — practically only via corrupted or non-standard range data.","commonSituations":"Rare: manually constructed csnet.Range values in tests or plugins; memory-corrupted or non-standard Addr; upstream csnet changes producing unexpected sizes.","solutions":["Ensure the range comes from csnet.NewRange or netip parsing, not hand-built addresses.","Log rng.Size() and rng.String() to identify the offending value.","If constructing ranges in code, validate the address family (Is4/Is6) before building the Range.","Report upstream if a valid parsed range yields an unexpected size."],"exampleFix":"// before\nrng := csnet.Range(netip.PrefixFrom(netip.AddrFrom4([4]byte{1,2,3,4}), 0)) // malformed\n// after\nrng, err := csnet.NewRange(\"1.2.3.0/24\")\nif err != nil { return err }","handlingStrategy":"validation","validationCode":"switch rng.Size() {\ncase 4, 16, 0:\n    // ok, safe to pass\ndefault:\n    return fmt.Errorf(\"range %q has unsupported size %d\", rng.String(), rng.Size())\n}","typeGuard":null,"tryCatchPattern":"q, err := decisionIPFilter(query, contains, rng)\nif err != nil {\n    if strings.Contains(err.Error(), \"unknown ip size\") {\n        return fmt.Errorf(\"rebuild range from a parsed IP: %w\", err)\n    }\n    return err\n}","preventionTips":["Always construct ranges via csnet.NewRange or netip parsing","Assert address family (Is4/Is6) before building ranges","Avoid hand-built netip.Addr values in plugins/tests","Add a size sanity check before invoking filter helpers"],"tags":["database","network","internal","filter"],"backgroundTag":"invalid-argument-value","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}