Changeset 525d09d


Ignore:
Timestamp:
09/30/14 15:14:02 (6 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
c69aecb
Parents:
092a09c
Message:

Better detection of truncation in libwandio zlib

Previously, we were returning "success" when reading from a truncated
gzip file and simply returning all bytes that we could successfully
decompress. This is not consistent with other gzip tools, which at least
alert that the file was not complete or the gzip integrity check was missing.

Now we will return an error if we hit an EOF in the gzip stream that is
not immediately preceded by a Z_STREAM_END marker and write an error message
to stderr so the user can know what has occurred.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libwandio/ior-zlib.c

    r60f3c4c r525d09d  
    5656        int outoffset;
    5757        enum err_t err;
     58        size_t sincelastend;
    5859};
    5960
     
    8384        DATA(io)->strm.opaque = NULL;
    8485        DATA(io)->err = ERR_OK;
     86        DATA(io)->sincelastend = 1;
    8587
    8688        inflateInit2(&DATA(io)->strm, 15 | 32);
     
    108110                                sizeof(DATA(io)->inbuff));
    109111                        if (bytes_read == 0) {
    110                                 /* EOF */
     112                                /* If we get EOF immediately after a
     113                                 * Z_STREAM_END, then we assume we've reached
     114                                 * the end of the file. If there was data
     115                                 * between the Z_STREAM_END and the EOF, the
     116                                 * file has more likely been truncated.
     117                                 */
     118                                if (DATA(io)->sincelastend > 0) {
     119                                        fprintf(stderr, "Unexpected EOF while reading compressed file -- file is probably incomplete\n");
     120                                        errno = EIO;
     121                                        DATA(io)->err = ERR_ERROR;
     122                                        return -1;
     123                                }
     124
     125                                /* EOF */
    111126                                if (DATA(io)->strm.avail_out == (uint32_t)len) {
    112                                         DATA(io)->err = ERR_EOF;
     127                                        DATA(io)->err = ERR_EOF;
    113128                                        return 0;
    114129                                }
     
    128143                        DATA(io)->strm.next_in = DATA(io)->inbuff;
    129144                        DATA(io)->strm.avail_in = bytes_read;
     145                        DATA(io)->sincelastend += bytes_read;
    130146                }
    131147                /* Decompress some data into the output buffer */
     
    144160                                inflateInit2(&DATA(io)->strm, 15 | 32);
    145161                                DATA(io)->err = ERR_OK;
     162                                DATA(io)->sincelastend = 0;
    146163                                break;
    147164                        default:
Note: See TracChangeset for help on using the changeset viewer.