commit 6bf3eb5ea1104f55279af5466d3b3aeecd910be8 parent e581bd7f4a8e38dcccfb0f1e5e1490c3df09a43b Author: Frederic Cambus <fred@statdns.com> Date: Wed, 7 Aug 2019 09:21:56 +0200 Exit with error if array index is invalid, it means input file is corrupt. Diffstat:
M | pcx2gba.c | | | 14 | ++++++++++++-- |
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/pcx2gba.c b/pcx2gba.c @@ -118,13 +118,23 @@ int main(int argc, char *argv[]) { run_count = current_byte-192; for (run_position = 0; run_position < run_count; run_position++) { - if (offset + run_position < pcx_buffer_size) + if (offset + run_position < pcx_buffer_size) { pcx_buffer[offset + run_position] = input_file_buffer[loop +1]; + } else { + printf("ERROR: Input File is corrupt\n\n"); + return EXIT_FAILURE; + } } offset += run_count; loop += 2; } else { - pcx_buffer[offset] = current_byte; + if (offset < pcx_buffer_size) { + pcx_buffer[offset] = current_byte; + } else { + printf("ERROR: Input File is corrupt\n\n"); + return EXIT_FAILURE; + } + offset++; loop++; }