{"record":{"id":"df82cb13a72ce7ae","repo":"dotnet/runtime","slug":"locale-info-for-locale-localename-exceeds-lengt","errorCode":null,"errorMessage":"Locale info for locale=${localeName} exceeds length of ${dstMaxLength}.","messagePattern":"Locale info for locale=(.+?) exceeds length of (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/globalization-locale.ts","lineNumber":85,"sourceCode":"                        return VoidPtrNull;\n                    }\n                    throw error;\n                }\n            } else {\n                throw error;\n            }\n        }\n        const localeInfo = {\n            LanguageName: languageName,\n            RegionName: regionName,\n        };\n        const result = Object.values(localeInfo).join(OUTER_SEPARATOR);\n\n        if (!result)\n            throw new Error(`Locale info for locale=${localeName} is null or empty.`);\n\n        if (result.length > dstMaxLength)\n            throw new Error(`Locale info for locale=${localeName} exceeds length of ${dstMaxLength}.`);\n\n        stringToUTF16(dst, dst + 2 * result.length, result);\n        setI32(dstLength, result.length);\n        return VoidPtrNull;\n    } catch (ex: any) {\n        setI32(dstLength, -1);\n        return stringToUTF16Ptr(ex.toString());\n    }\n}\n","sourceCodeStart":67,"sourceCodeEnd":95,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/mono/browser/runtime/globalization-locale.ts#L67-L95","documentation":"Thrown by SystemJS_GetLocaleInfo in globalization-locale.ts when the resolved locale info string (LanguageName##RegionName) is longer than dstMaxLength, the managed-side destination buffer capacity. The check protects against buffer overflow when marshalling the result back to managed memory. Caught locally, reported to managed code via dstLength=-1 and the error string.","triggerScenarios":"Managed code allocated a destination buffer too small for the localized display names; very long language/region display names (some locales produce multi-word names); a downstream change that increased display-name length without resizing the native buffer.","commonSituations":"A runtime/SDK update that changed ICU display-name formatting so results grew; a custom marshaler with a hardcoded buffer size; locales with long names (e.g. some zh-Hant names) against a too-small buffer.","solutions":["Increase the destination buffer size (dstMaxLength) on the managed side that calls the interop.","Update the .NET runtime to a version whose managed caller allocates a correctly sized buffer.","If using a custom interop wrapper, size the buffer from the locale string length plus headroom."],"exampleFix":"// before: fixed 64-char buffer\nvar buf = new string('\\0', 64);\n// after: size generously for display names\nvar buf = new string('\\0', 512);","handlingStrategy":"validation","validationCode":"// managed side: allocate a buffer large enough for localized names\nconst int MaxLocaleInfoLength = 512;\nvar dst = new string('\\0', MaxLocaleInfoLength);","typeGuard":null,"tryCatchPattern":"// forwarded via dstLength=-1; caller checks that and resizes/retries\nif (dstLength == -1) { /* increase buffer, retry once */ }","preventionTips":["Size locale-info buffers generously (>= 256 chars).","Keep the runtime and its managed caller from the same build so buffer sizing stays consistent.","Treat dstLength=-1 as a recoverable signal and fall back to the raw locale code."],"tags":["globalization","marshalling","buffer-overflow","locale"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}