hvif2png: Input file reading fix, file magic check

* Fix an infinite loop on reading a larger file.
* Check hvif magic number

Ticket #12207.

Signed-off-by: Ingo Weinhold <ingo_weinhold@gmx.de>
This commit is contained in:
Andrew Lindesay 2015-07-18 23:31:07 +12:00 committed by Ingo Weinhold
parent a3b04ab398
commit 874bb4ede9
1 changed files with 21 additions and 0 deletions

View File

@ -31,6 +31,9 @@
#define SIZE_HVIF_BUFFER_STEP 1024
static const uint8 kHvifMagic[] = { 'n', 'c', 'i', 'f' };
typedef struct h2p_hvif_buffer {
uint8* buffer;
size_t used;
@ -195,6 +198,8 @@ h2p_read_hvif_input(h2p_hvif_buffer* result, FILE* in)
fprintf(stderr,"out of memory\n");
return 0;
}
result->allocated += SIZE_HVIF_BUFFER_STEP;
}
result->used += fread(&result->buffer[result->used], sizeof(uint8),
@ -208,6 +213,22 @@ h2p_read_hvif_input(h2p_hvif_buffer* result, FILE* in)
}
}
if (result->used < 4) {
fprintf(stderr, "the hvif data is too small to visably be valid\n");
return 0;
}
// hvif files have a magic string of "ncif" so we should check for that as
// well.
if (memcmp(result->buffer, kHvifMagic, 4) != 0) {
fprintf(stderr, "the input data does not look like hvif because the"
" magic string is not 'ncif'; %d, %d, %d, %d\n",
result->buffer[0], result->buffer[1], result->buffer[2],
result->buffer[3]);
return 0;
}
return result->used;
}