Skip to content

Commit

Permalink
hvif2png: Input file reading fix, file magic check
Browse files Browse the repository at this point in the history
* Fix an infinite loop on reading a larger file.
* Check hvif magic number

Ticket #12207.

Signed-off-by: Ingo Weinhold <ingo_weinhold@gmx.de>
  • Loading branch information
andponlin authored and weinhold committed Jul 19, 2015
1 parent a3b04ab commit 874bb4e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/tools/hvif2png/hvif2png.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand All @@ -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;
}

Expand Down

0 comments on commit 874bb4e

Please sign in to comment.