{"record":{"id":"fa9501d6eac2bef3","repo":"gchq/CyberChef","slug":"character-at-position-i-exceeds-latin-1-range","errorCode":null,"errorMessage":"Character at position ${i} exceeds Latin-1 range (0-255).\nOnly ASCII and Latin-1 characters are supported.","messagePattern":"Character at position (.+?) exceeds Latin-1 range \\(0-255\\)\\.\nOnly ASCII and Latin-1 characters are supported\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/TextIntegerConverter.mjs","lineNumber":22,"sourceCode":" * @license Apache-2.0\n */\n\nimport Operation from \"../Operation.mjs\";\nimport OperationError from \"../errors/OperationError.mjs\";\n\n/* ---------- helper functions ---------- */\n\n/**\n * Convert text to BigInt (big-endian byte interpretation)\n */\nfunction textToBigInt(text) {\n    if (text.length === 0) return 0n;\n\n    let result = 0n;\n    for (let i = 0; i < text.length; i++) {\n        const charCode = BigInt(text.charCodeAt(i));\n        if (charCode > 255n) {\n            throw new OperationError(\n                `Character at position ${i} exceeds Latin-1 range (0-255).\\n` +\n                \"Only ASCII and Latin-1 characters are supported.\");\n        }\n        result = (result << 8n) | charCode;\n    }\n    return result;\n}\n\n/**\n * Convert BigInt to text (big-endian byte interpretation)\n */\nfunction bigIntToText(value) {\n    if (value === 0n) return \"\";\n\n    const bytes = [];\n    let num = value;\n\n    while (num > 0n) {","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/TextIntegerConverter.mjs#L4-L40","documentation":"TextIntegerConverter's text-to-BigInt path interprets each character as a single byte (big-endian). Any character whose code point exceeds 255 — i.e. anything outside Latin-1 such as emoji, CJK characters, or accented characters above U+00FF — is rejected, because it cannot fit in one byte of the resulting integer.","triggerScenarios":"Passing input containing characters with charCodeAt > 255 to the Text -> BigInt direction. Examples: emoji (U+1F600), Chinese characters, the Euro sign (U+20AC), or curly quotes.","commonSituations":"Pasting rich/Unicode text from a word processor; receiving UTF-8 multibyte text where the source intent was ASCII; mixing encodings.","solutions":["Strip or replace non-Latin-1 characters before conversion.","Convert the input to UTF-8 bytes first via a 'To Hex' / UTF-8 path, then treat the bytes as the integer.","Restrict input to ASCII / Latin-1 (code points 0-255)."],"exampleFix":"// before: input = \"café\\u20AC\"  (€ is U+20AC > 255) -> throws at the € position\n// after:  input = \"cafe\"         (ASCII only)            -> converts successfully","handlingStrategy":"validation","validationCode":"for (let i = 0; i < text.length; i++) {\n  if (text.charCodeAt(i) > 255) throw new Error(`Non-Latin-1 char at ${i}`);\n}","typeGuard":"const isLatin1 = text => [...text].every(c => c.charCodeAt(0) <= 255);","tryCatchPattern":"try { textToBigInt(text); }\ncatch (e) { if (/Latin-1/.test(e.message)) { text = text.replace(/[^\\u0000-\\u00ff]/g, \"\"); } else throw e; }","preventionTips":["Sanitise input to Latin-1 before conversion.","Encode multibyte text as UTF-8 bytes first if full Unicode is needed.","Reject non-ASCII at the form boundary."],"tags":["encoding","latin1","bigint","unicode","validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}