From 141d0bf698f15c98313f9225f5f2aaff82a869db Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 23 Feb 2018 01:22:42 +0100 Subject: [PATCH] parseiff: try to parse after the theorical end of the file some malformed IFF files are like this --- tools/test_iff/parseiff.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/tools/test_iff/parseiff.c b/tools/test_iff/parseiff.c index d9ab2a5a..46c5b908 100644 --- a/tools/test_iff/parseiff.c +++ b/tools/test_iff/parseiff.c @@ -81,11 +81,11 @@ static int parseiff_chunks(FILE * f, uint32_t size, int level) char section[4]; uint32_t section_size; - if (size&1) - { - fprintf(stderr, "WARNING: odd size of Container chunk, adjusting\n"); - size++; - } + //if (size&1) + //{ + // fprintf(stderr, "WARNING: odd size of Container chunk, adjusting\n"); + // size++; + //} index = 0; while (size >= 8) { @@ -115,7 +115,8 @@ static int parseiff_chunks(FILE * f, uint32_t size, int level) else { printf("%.4s %u\n", section, section_size); - section_size = (section_size+1)&~1; // round to WORD boundary + if ((size & 1) == 0) // if container has EVEN size + section_size = (section_size+1)&~1; // round to WORD boundary fseek(f, section_size, SEEK_CUR); } if (section_size > size) @@ -173,6 +174,17 @@ int parseiff(FILE * f) offset = ftell(f); fseek(f, 0, SEEK_END); file_size = ftell(f); + fseek(f, offset, SEEK_SET); + if (file_size > offset + 8) + { + fprintf(stderr, "Tying to parse the %ld extra bytes.\n", file_size - offset); + r = parseiff_chunks(f, file_size - offset, 0); + if (r < 0) + return r; + } + offset = ftell(f); + fseek(f, 0, SEEK_END); + file_size = ftell(f); if (offset != file_size) { fprintf(stderr, "parsed %ld bytes, but file is %ld bytes long.\n", offset, file_size);