EILSEQ
Linux / POSIXERRORNotableEncodingHIGH confidence

Invalid or Incomplete Multibyte or Wide Character

Production Risk

Common when processing user-supplied text without encoding validation.

What this means

EILSEQ (errno 84) is returned when a character encoding conversion encounters an invalid byte sequence that does not correspond to any valid multibyte character in the current locale.

Why it happens
  1. 1Passing invalid UTF-8 bytes to iconv() or mbstowcs()
  2. 2Reading a file with one encoding while the locale expects another
  3. 3Truncated multibyte sequence at buffer boundary
How to reproduce

iconv() converting bytes that are not valid UTF-8.

trigger — this will error
trigger — this will error
// Attempt to convert invalid UTF-8 bytes
iconv_t cd = iconv_open("UTF-32", "UTF-8");
char in[] = {0xFF, 0xFE, 0x00};  // invalid UTF-8
char *inbuf = in; size_t inl = 3;
char out[64]; char *outbuf = out; size_t outl = 64;
iconv(cd, &inbuf, &inl, &outbuf, &outl);
// Returns -1, errno = EILSEQ

expected output

iconv: Invalid or incomplete multibyte or wide character (EILSEQ)

Fix

Validate encoding before conversion

WHEN Before passing user-supplied data to iconv()

Validate encoding before conversion
// Use iconv with IGNORE or TRANSLIT to skip bad chars
iconv_t cd = iconv_open("UTF-8//IGNORE", "UTF-8");
// Or use Python/Node for robust encoding detection
# Python: detect encoding first
import chardet
enc = chardet.detect(data)['encoding']

Why this works

//IGNORE suffix skips unconvertible sequences; //TRANSLIT substitutes with similar characters.

What not to do

Ignore EILSEQ and use partial output

Partial output is truncated or corrupted; the conversion did not complete.

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Linux / POSIX errors