gbaconv

A set of tools aimed at GameBoy Advance developers
Log | Files | Refs | README | LICENSE

commit 6b8c1d010c70738c9faf1aeeffdbc2dab17e6a8a
parent a651866338d532f179aa827e4bc7575c2c9ce875
Author: Frederic Cambus <fred@statdns.com>
Date:   Sat, 23 Mar 2019 19:17:01 +0100

Add more format checks to ensure input file is a valid PCX file.

Diffstat:
Mpcx2gba.c | 14++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/pcx2gba.c b/pcx2gba.c @@ -75,6 +75,11 @@ int main(int argc, char *argv[]) { return 1; } + if (st.st_size < PCX_HEADER_LENGTH + PCX_PALETTE_LENGTH) { + printf("ERROR: Input File is not a PCX file\n\n"); + return 1; + } + /* mmap input file into memory */ input_file_buffer = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (input_file_buffer == MAP_FAILED) { @@ -82,14 +87,15 @@ int main(int argc, char *argv[]) { return 1; } - if (st.st_size < PCX_HEADER_LENGTH + PCX_PALETTE_LENGTH) { + memcpy(&pcx_header, input_file_buffer, PCX_HEADER_LENGTH); + + /* Check that the file is a valid PCX file */ + if (pcx_header.ID != 10) { printf("ERROR: Input File is not a PCX file\n\n"); return 1; } - /* Check that the file is a valid 8-bpp PCX */ - memcpy(&pcx_header, input_file_buffer, PCX_HEADER_LENGTH); - + /* Check that the file is a 8-bpp PCX */ if (pcx_header.bits_per_pixel != 8) { printf("ERROR: Input File is not 8-bpp\n\n"); return 1;