{"record":{"id":"066303dc48180a6a","repo":"prestodb/presto","slug":"generic-internal-error-066303","errorCode":"GENERIC_INTERNAL_ERROR","errorMessage":"Invalid InetAddress length: ${addressLength}","messagePattern":"Invalid InetAddress length: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"warning","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/scalar/IpPrefixFunctions.java","lineNumber":136,"sourceCode":"    }\n\n    private IpPrefixFunctions() {}\n\n    @Description(\"IP prefix for a given IP address and subnet size\")\n    @ScalarFunction(\"ip_prefix\")\n    @SqlType(StandardTypes.IPPREFIX)\n    public static Slice ipPrefix(@SqlType(StandardTypes.IPADDRESS) Slice value, @SqlType(StandardTypes.BIGINT) long subnetSize)\n    {\n        InetAddress address = toInetAddress(value);\n        int addressLength = address.getAddress().length;\n        if (addressLength == 4) {\n            checkCondition(0 <= subnetSize && subnetSize <= 32, INVALID_FUNCTION_ARGUMENT, \"IPv4 subnet size must be in range [0, 32]\");\n        }\n        else if (addressLength == 16) {\n            checkCondition(0 <= subnetSize && subnetSize <= 128, INVALID_FUNCTION_ARGUMENT, \"IPv6 subnet size must be in range [0, 128]\");\n        }\n        else {\n            throw new PrestoException(GENERIC_INTERNAL_ERROR, \"Invalid InetAddress length: \" + addressLength);\n        }\n\n        return castFromVarcharToIpPrefix(utf8Slice(InetAddresses.toAddrString(address) + \"/\" + subnetSize));\n    }\n\n    @Description(\"IP prefix for a given IP address and subnet size\")\n    @ScalarFunction(\"ip_prefix\")\n    @LiteralParameters(\"x\")\n    @SqlType(StandardTypes.IPPREFIX)\n    public static Slice stringIpPrefix(@SqlType(\"varchar(x)\") Slice slice, @SqlType(StandardTypes.BIGINT) long subnetSize)\n    {\n        return ipPrefix(castFromVarcharToIpAddress(slice), subnetSize);\n    }\n\n    @Description(\"Smallest IP address for a given IP prefix\")\n    @ScalarFunction(\"ip_subnet_min\")\n    @SqlType(StandardTypes.IPADDRESS)\n    public static Slice ipSubnetMin(@SqlType(StandardTypes.IPPREFIX) Slice value)","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/IpPrefixFunctions.java#L118-L154","documentation":"Internal ip_prefix construction validates the raw InetAddress length (4 for IPv4, 16 for IPv6) before applying subnet bounds. Any other length indicates an unexpected address representation, so Presto throws GENERIC_INTERNAL_ERROR. This should be unreachable via normal SQL input and usually indicates a bug or corrupted IPPREFIX/VARCHAR data.","triggerScenarios":"Calling ip_prefix(varchar, integer) where the parsed InetAddress has a byte length other than 4 or 16 — only possible through an internal/decoder bug or corrupted input, since normal parse paths yield only IPv4/IPv6 addresses.","commonSituations":"Custom address parsing extensions feeding malformed bytes; engine bugs in InetAddress decoding; upstream data corruption reaching an unexpected code path.","solutions":["Verify the address string passed to ip_prefix() is a well-formed IPv4 or IPv6 literal.","If inputs come from a UDF/connector, check that it returns standard IP strings.","Report as a bug with the offending input if a normal IP string triggers it."],"exampleFix":"// before\nSELECT ip_prefix(address_col, 24) -- address_col contains non-standard bytes\n// after\nSELECT ip_prefix(CAST(address_col AS VARCHAR), 24) -- with validated IP strings","handlingStrategy":"validation","validationCode":"-- ensure the input parses to a normal IPv4/IPv6 address first\nSELECT ip_prefix(CAST(address AS VARCHAR), 24) FROM t WHERE address LIKE '%.%' OR address LIKE '%:%'","typeGuard":null,"tryCatchPattern":"// client\ntry {\n    executeQuery(\"SELECT ip_prefix(addr, 24) FROM t\");\n} catch (QueryFailedException e) {\n    // GENERIC_INTERNAL_ERROR here indicates a decoder bug; report with the input\n}","preventionTips":["Only feed well-formed IPv4/IPv6 literals into ip_prefix()","Sanitize connector/UDF outputs that feed address columns","Report to maintainers if a plain IP string triggers this internal error"],"tags":["presto","ip-prefix","internal-error","ip-address"],"backgroundTag":"invalid-ip-address","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}