{"record":{"id":"7d0ad8c3985d509b","repo":"chinabugotech/hutool","slug":"overflow","errorCode":null,"errorMessage":"OVERFLOW","messagePattern":"OVERFLOW","errorType":"exception","errorClass":"UtilException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/codec/PunyCode.java","lineNumber":105,"sourceCode":"\t\tif (b > 0) {\n\t\t\tif(b == length){\n\t\t\t\t// 无需要编码的字符\n\t\t\t\treturn output.toString();\n\t\t\t}\n\t\t\toutput.append(DELIMITER);\n\t\t}\n\t\tint h = b;\n\t\twhile (h < length) {\n\t\t\tint m = Integer.MAX_VALUE;\n\t\t\t// Find the minimum code point >= n\n\t\t\tfor (int i = 0; i < length; i++) {\n\t\t\t\tfinal char c = input.charAt(i);\n\t\t\t\tif (c >= n && c < m) {\n\t\t\t\t\tm = c;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (m - n > (Integer.MAX_VALUE - delta) / (h + 1)) {\n\t\t\t\tthrow new UtilException(\"OVERFLOW\");\n\t\t\t}\n\t\t\tdelta = delta + (m - n) * (h + 1);\n\t\t\tn = m;\n\t\t\tfor (int j = 0; j < length; j++) {\n\t\t\t\tint c = input.charAt(j);\n\t\t\t\tif (c < n) {\n\t\t\t\t\tdelta++;\n\t\t\t\t\tif (0 == delta) {\n\t\t\t\t\t\tthrow new UtilException(\"OVERFLOW\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (c == n) {\n\t\t\t\t\tint q = delta;\n\t\t\t\t\tfor (int k = BASE; ; k += BASE) {\n\t\t\t\t\t\tint t;\n\t\t\t\t\t\tif (k <= bias) {\n\t\t\t\t\t\t\tt = TMIN;\n\t\t\t\t\t\t} else if (k >= bias + TMAX) {","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/codec/PunyCode.java#L87-L123","documentation":"Thrown by PunyCode.encode() when the delta value would overflow Integer.MAX_VALUE during the Punycode encoding loop. Specifically when (m - n) exceeds the safe remaining capacity divided by (h + 1). This is a guard against arithmetic overflow per the RFC 3492 specification. It indicates the input is pathologically large or contains code points that cause extreme delta accumulation.","triggerScenarios":"Encoding a CharSequence with a very large number of non-ASCII characters or extremely high Unicode code points that cause the delta arithmetic to exceed Integer.MAX_VALUE. This is theoretically possible with adversarial input or very long Unicode strings.","commonSituations":"Processing extremely long internationalized domain name (IDN) labels. Adversarial input designed to trigger integer overflow. In practice, normal domain names and Unicode strings will never hit this limit because the input length bounds are well within safe range for int arithmetic.","solutions":["Catch UtilException around the encode call and report the input as too large to encode.","Validate input length before encoding — reject strings longer than a reasonable domain label limit (253 chars for FQDN, 63 per label).","Split very long inputs into smaller segments before encoding."],"exampleFix":"// before\nString punycode = PunyCode.encode(veryLongUnicodeString); // may throw OVERFLOW\n\n// after\ntry {\n    String punycode = PunyCode.encode(veryLongUnicodeString);\n} catch (UtilException e) {\n    if (\"OVERFLOW\".equals(e.getMessage())) {\n        // input too large, reject or split\n        throw new IllegalArgumentException(\"Input too large for Punycode encoding\", e);\n    }\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"// Limit input length to prevent overflow\nif (input.length() > 1000) {\n    throw new IllegalArgumentException(\"Input too long for Punycode encoding\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    String encoded = PunyCode.encode(input);\n} catch (UtilException e) {\n    if (\"OVERFLOW\".equals(e.getMessage())) {\n        throw new IllegalArgumentException(\"Input too large\", e);\n    }\n    throw e;\n}","preventionTips":["Limit input length before encoding.","Use encodeDomain() for domain processing to split into smaller labels.","Prefer java.net.IDN for production domain handling."],"tags":["punycode","encode","overflow","idn","codec"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}