diff options
author | Yann Collet <cyan@fb.com> | 2018-09-05 23:45:46 (GMT) |
---|---|---|
committer | Yann Collet <cyan@fb.com> | 2018-09-05 23:45:46 (GMT) |
commit | 858b6ad7f3f9aae072bccc1dbc484cbc2793a45a (patch) | |
tree | bfe1526391e5c2872440504b80273a6f741f2a88 /examples/frameCompress.c | |
parent | 0d1ced5b0c2b87b672b70946fbc5ef41403cae98 (diff) | |
download | lz4-858b6ad7f3f9aae072bccc1dbc484cbc2793a45a.zip lz4-858b6ad7f3f9aae072bccc1dbc484cbc2793a45a.tar.gz lz4-858b6ad7f3f9aae072bccc1dbc484cbc2793a45a.tar.bz2 |
frameCompress : added an error detection case
check for potential input data not consumed.
Diffstat (limited to 'examples/frameCompress.c')
-rw-r--r-- | examples/frameCompress.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/examples/frameCompress.c b/examples/frameCompress.c index a97dc72..a0c5d3d 100644 --- a/examples/frameCompress.c +++ b/examples/frameCompress.c @@ -195,7 +195,7 @@ decompress_file_internal(FILE* f_in, FILE* f_out, * Continue while there is more input to read (srcPtr != srcEnd) * and the frame isn't over (ret != 0) */ - while (srcPtr != srcEnd && ret != 0) { + while (srcPtr < srcEnd && ret != 0) { /* Any data within dst has been flushed at this stage */ size_t dstSize = dstCapacity; size_t srcSize = srcEnd - srcPtr; @@ -209,9 +209,20 @@ decompress_file_internal(FILE* f_in, FILE* f_out, /* Update input */ srcPtr += srcSize; } + + assert(srcPtr <= srcEnd); + + /* Ensure all input data has been consumed. + * It is valid to have multiple frames in the same file, + * but this example only supports one frame. + */ + if (srcPtr < srcEnd) { + printf("Decompress: Trailing data left in file after frame\n"); + return 1; + } } - /* Check that there isn't trailing input data after the frame. + /* Check that there isn't trailing data in the file after the frame. * It is valid to have multiple frames in the same file, * but this example only supports one frame. */ |