Logo Search packages:      
Sourcecode: tardy version File versions  Download package

void tar_input_filter_gunzip::read_data_padding (  )  [virtual]

The read_data_padding is used to read any extra data between files. By default, this method does nothing.

Reimplemented from tar_input_filter.

Definition at line 446 of file gunzip.cc.

References buf, buffered_read(), crc, deflated_file_length, deflated_file_pos, tar_input::fatal(), get_long(), inflated_file_length, inflated_file_pos, pass_through, tar_input_filter::read_data_padding(), stream, z_eof, and zlib_fatal_error().

{
    if (pass_through || z_eof)
    {
      tar_input_filter::read_data_padding();
      return;
    }

    /*
     * We should be exactly at the end of input.
     * So we need to read the length and CRC fields to check.
     * To do this, we need a dummy buffer for decompressed data.
     */
    char data[4];
    stream.next_out = (Bytef *)data;
    stream.avail_out = sizeof(data);

    if (stream.avail_in == 0)
    {
      // assert(buf);
      stream.next_in = buf;
      stream.avail_in = buffered_read(buf, Z_BUFSIZE);

      /*
       * There should always be something left on the
       * input, because we have the CRC and Length
       * to follow.  Fatal error if not.
       */
      if (stream.avail_in <= 0)
          fatal("premature end of file");
    }
    int err = inflate(&stream, Z_PARTIAL_FLUSH);
    if (err < 0)
      zlib_fatal_error(err);
    if (err != Z_STREAM_END || stream.next_out != (Bytef *)data)
      fatal("gunzip: too much deflated file");

    /*
     * Check CRC
     *
     * Watch out for 64-bit machines.  This is what
     * those aparrently redundant 0xFFFFFFFF are for.
     */
    if ((get_long() & 0xFFFFFFFF) != (crc & 0xFFFFFFFF))
      fatal("gunzip: checksum mismatch");

    /*
     * The uncompressed length here may be different
     * from pos in case of concatenated .gz
     * files.  But we don't write them that way,
     * so give an error if it happens.
     *
     * We shouldn't have 64-bit problems in this case.
     */
    if (get_long() != inflated_file_pos)
      fatal("gunzip: length mismatch");
    if (inflated_file_pos != inflated_file_length)
      fatal("inflated length mismatch");
    if (deflated_file_pos != deflated_file_length)
      fatal("deflated length mismatch");

    /*
     * Finished with this stream.
     */
    err = inflateEnd(&stream);
    if (err < 0)
      zlib_fatal_error(err);

    /*
     * Now read the deeper padding
     */
    tar_input_filter::read_data_padding();
}


Generated by  Doxygen 1.6.0   Back to index