NationalSecurityAgency/ghidra · error
need even-number of ascii chars for byte-stream: (offset: %0
Error message
need even-number of ascii chars for byte-stream: (offset: %08lx, %s, %ld)\n
What it means
gdis validation error: the ascii byte-string has an odd number of characters, so it cannot be decoded into whole bytes (each byte = 2 hex chars). The program prints the offset, the buffer, and its length, then calls exit(-1).
Source
Thrown at GPL/GnuDisassembler/src/gdis/c/disasm_1.c:376
}
else {
fprintf(stderr, "exiting, no ASCII hex found\n");
return 0; // finished! #TODO
}
}
else {
if(strlen(byteString) > BYTE_BUFFER_SIZE*2) {
fprintf(stderr, "Max ascii string size is %d you provided: %lu chars. Exiting.\n", BYTE_BUFFER_SIZE*2,
strlen(byteString));
exit(-1);
}
strncpy(byteStringBuffer, byteString, BYTE_BUFFER_SIZE*2);
stdin_mode = 0; // break out of the while loop
}
int size = strlen(byteStringBuffer);
if((size % 2) != 0){
fprintf(stderr, "need even-number of ascii chars for byte-stream: (offset: %08lx, %s, %ld)\n", offset, byteStringBuffer, strlen(byteStringBuffer));
exit(-1);
}
memset(byteBuffer, 0x00, BYTE_BUFFER_SIZE);
//
// TODO:
// check to make sure chars are only valid HEX.
//
int i, j;
for(i=j=0; (i < size) && (j < BYTE_BUFFER_SIZE); i+=2, j++){
tmp[0] = byteStringBuffer[i];
tmp[1] = byteStringBuffer[i+1];
tmp[2] = 0;
sscanf(tmp, "%02X", &byteValue);
byteBuffer[j] = (unsigned char)byteValue;
}
View on GitHub (pinned to d5f144c24d)
Solutions
- Make the hex string length even by removing the trailing nibble or padding with a leading '0'.
- Validate `strlen(str) % 2 == 0` in the caller/wrapper before invoking gdis.
- Regenerate the byte string from the original binary to avoid partial bytes.
- Add a preflight check in your script that rejects odd-length input.
Example fix
// before $ gdis ... 90901 // 5 chars -> odd // after $ gdis ... 9090 // drop stray nibble // or $ gdis ... 090901 // pad to even
Defensive patterns
Strategy: validation
Validate before calling
size_t n = strlen(byteString);
if (n % 2 != 0) {
fprintf(stderr, "odd-length hex string (%zu)\n", n);
return 2;
} Prevention
- Validate even length in the caller/wrapper.
- Generate hex from raw bytes with a %02x formatter to avoid partial bytes.
- Reject non-hex characters too (the source marks this as a TODO).
When it happens
Trigger: Passing/piping a hex string whose length is odd, e.g. '9090' is fine but '90901' (5 chars) triggers it.
Common situations: A stray nibble from a copy-paste; a hex-dump tool that emits a partial final byte; truncation of the string at a non-even boundary.
Related errors
- Max ascii string size is %d you provided: %lu chars. Exiting
- Usage: %s target-str, arch, mach, disassembly base-addr (for
- exiting, no ASCII hex found\n
- %s: unknown demangling style `%s'
- %s: unrecognized option `--%s'
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/4764b6f414483dd1.
Report an issue: GitHub.