gchq/CyberChef · error · OperationError
Character at position ${i} exceeds Latin-1 range (0-255). On
Error message
Character at position ${i} exceeds Latin-1 range (0-255).
Only ASCII and Latin-1 characters are supported. What it means
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.
Source
Thrown at src/core/operations/TextIntegerConverter.mjs:22
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
/* ---------- helper functions ---------- */
/**
* Convert text to BigInt (big-endian byte interpretation)
*/
function textToBigInt(text) {
if (text.length === 0) return 0n;
let result = 0n;
for (let i = 0; i < text.length; i++) {
const charCode = BigInt(text.charCodeAt(i));
if (charCode > 255n) {
throw new OperationError(
`Character at position ${i} exceeds Latin-1 range (0-255).\n` +
"Only ASCII and Latin-1 characters are supported.");
}
result = (result << 8n) | charCode;
}
return result;
}
/**
* Convert BigInt to text (big-endian byte interpretation)
*/
function bigIntToText(value) {
if (value === 0n) return "";
const bytes = [];
let num = value;
while (num > 0n) {View on GitHub (pinned to 4290ea7539)
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).
Example fix
// before: input = "café\u20AC" (€ is U+20AC > 255) -> throws at the € position // after: input = "cafe" (ASCII only) -> converts successfully
Defensive patterns
Strategy: validation
Validate before calling
for (let i = 0; i < text.length; i++) {
if (text.charCodeAt(i) > 255) throw new Error(`Non-Latin-1 char at ${i}`);
} Type guard
const isLatin1 = text => [...text].every(c => c.charCodeAt(0) <= 255);
Try / catch
try { textToBigInt(text); }
catch (e) { if (/Latin-1/.test(e.message)) { text = text.replace(/[^\u0000-\u00ff]/g, ""); } else throw e; } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Pasting rich/Unicode text from a word processor; receiving UTF-8 multibyte text where the source intent was ASCII; mixing encodings.
Related errors
- Unknown Normalisation Form
- Invalid Base64 alphabet length (${alphabet.length}): ${alpha
- Byte length must be a positive integer
- unexpected character encountered: "${character}"
- Invalid custom CRC arguments
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/fa9501d6eac2bef3.
Report an issue: GitHub.