{"record":{"id":"bc74bc2e23df792f","repo":"NationalSecurityAgency/ghidra","slug":"max-ascii-string-size-is-d-you-provided-lu-char","errorCode":null,"errorMessage":"Max ascii string size is %d you provided: %lu chars. Exiting.\\n","messagePattern":"Max ascii string size is (.+?) you provided: %lu chars\\. Exiting\\.\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"GPL/GnuDisassembler/src/gdis/c/disasm_1.c","lineNumber":366,"sourceCode":"\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\t//no \"*\" in the string, so no disassembly options\n\t\t\t\t\t//replace newline with null terminator\n\t\t\t\t\tstrncpy(byteStringBuffer, bytesAndOptionsBuffer, sizeof(byteStringBuffer));\n\t\t\t\t\tp = strchr(byteStringBuffer,'\\n');\n\t\t\t\t\tif (p){\n\t\t\t\t\t\t*p = '\\0';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tfprintf(stderr, \"exiting, no ASCII hex found\\n\");\n\t\t\t\treturn 0; // finished! #TODO\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif(strlen(byteString) > BYTE_BUFFER_SIZE*2) {\n\t\t\t\tfprintf(stderr, \"Max ascii string size is %d you provided: %lu chars. Exiting.\\n\", BYTE_BUFFER_SIZE*2,\n\t\t\t\t\t\tstrlen(byteString));\n\t\t\t\texit(-1);\n\t\t\t}\n\t\t\tstrncpy(byteStringBuffer, byteString, BYTE_BUFFER_SIZE*2);\n\t\t\tstdin_mode = 0; // break out of the while loop\n\t\t}\n\n\t\tint size = strlen(byteStringBuffer);\n\t\tif((size % 2) != 0){\n\t\t\tfprintf(stderr, \"need even-number of ascii chars for byte-stream: (offset: %08lx, %s, %ld)\\n\", offset, byteStringBuffer, strlen(byteStringBuffer));\n\t\t\texit(-1);\n\t\t}\n\n\t\tmemset(byteBuffer, 0x00, BYTE_BUFFER_SIZE);\n\n\t\t//\n\t\t// TODO:\n\t\t// check to make sure chars are only valid HEX.","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/GPL/GnuDisassembler/src/gdis/c/disasm_1.c#L348-L384","documentation":"gdis validation error in argument mode. The supplied ascii byte-string length exceeds BYTE_BUFFER_SIZE*2 (two hex chars per byte). The program prints the limit and the actual length then calls exit(-1), terminating the process immediately.","triggerScenarios":"Passing a byte-string (argv[7]) longer than BYTE_BUFFER_SIZE*2 characters in non-stdin mode.","commonSituations":"Disassembling a very large code region in one shot; wrong buffer-size constant; a script concatenating many hex strings without truncation.","solutions":["Shorten the byte-string to at most BYTE_BUFFER_SIZE*2 hex characters.","Increase BYTE_BUFFER_SIZE in the source and rebuild if a larger region is legitimately needed.","Split the input into chunks and invoke gdis once per chunk.","Switch to stdin mode which reads into bytesAndOptionsBuffer of related size if that fits better."],"exampleFix":"// before (constant too small for the input)\n#define BYTE_BUFFER_SIZE 256   // allows 512 hex chars; user passes 600\n\n// after\n#define BYTE_BUFFER_SIZE 512    // allows 1024 hex chars\n// (rebuild gdis)","handlingStrategy":"validation","validationCode":"size_t n = strlen(byteString);\nif (n > BYTE_BUFFER_SIZE * 2) {\n  fprintf(stderr, \"byte string too long (%zu > %d)\\n\", n, BYTE_BUFFER_SIZE*2);\n  return 2;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check length in the caller before invoking gdis.","Chunk large regions into multiple invocations.","Size BYTE_BUFFER_SIZE to your largest expected region."],"tags":["cli","disassembler","validation","buffer-overflow-prevention","c"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}