[haiku-commits] haiku: hrev49417 - src/tools/hvif2png

  • From: ingo_weinhold@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 19 Jul 2015 11:43:45 +0200 (CEST)

hrev49417 adds 1 changeset to branch 'master'
old head: a3b04ab3986879be284400cd130985f9e955dad1
new head: 874bb4ede91e5847b4ae40c3459b356be045ecf8
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=874bb4ede91e+%5Ea3b04ab39868

----------------------------------------------------------------------------

874bb4ede91e: 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@xxxxxx>

[ Andrew Lindesay <apl@xxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision: hrev49417
Commit: 874bb4ede91e5847b4ae40c3459b356be045ecf8
URL: http://cgit.haiku-os.org/haiku/commit/?id=874bb4ede91e
Author: Andrew Lindesay <apl@xxxxxxxxxxxxxx>
Date: Sat Jul 18 11:31:07 2015 UTC
Committer: Ingo Weinhold <ingo_weinhold@xxxxxx>
Commit-Date: Sun Jul 19 09:42:18 2015 UTC

Ticket: https://dev.haiku-os.org/ticket/12207

----------------------------------------------------------------------------

1 file changed, 21 insertions(+)
src/tools/hvif2png/hvif2png.cpp | 21 +++++++++++++++++++++

----------------------------------------------------------------------------

diff --git a/src/tools/hvif2png/hvif2png.cpp b/src/tools/hvif2png/hvif2png.cpp
index 70135bc..1dca2ec 100644
--- a/src/tools/hvif2png/hvif2png.cpp
+++ b/src/tools/hvif2png/hvif2png.cpp
@@ -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;
}



Other related posts: