commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <bode...@apache.org>
Subject Re: [compress] any checksums in bz2 or gz tarballs? ...
Date Fri, 17 Jun 2011 12:57:22 GMT
On 2011-06-15, Albretch Mueller wrote:

> based on the data definifion of the struct holding TarArchiveEntry's
> properties:
> http://commons.apache.org/compress/apidocs/org/apache/commons/compress/archivers/tar/TarArchiveEntry.html

> TarArchive entries, as zip ones, should have some checksum mechanism.
> However, in the API I don't see a way to "get" it and "check"

Commons Compress currently explicitly skips over the checksum field when
parsing the tar entry, it doesn't check it, it doesn't even read it at
all.  So there not only is no way inside the API to access it, Commons
Compress completely ignores it when reading.

Things are different when Commons Compress writes tar archives as it
computes the checksum and writes it.


> Zip files hace Adler and/or CRC32 checksums

The algorithm used in tar's is way less advanced, at least if the
implementation on Commons Compress is correct, which I believe it to be.
If I read the code correctly the checksum (unlike that in ZIPs) doesn't
apply to the entry's contents but only to the header data which limits
its usefulness.

[This is from TarUtils.java]

    private static final int BYTE_MASK = 255;

    /**
     * Compute the checksum of a tar entry header.
     *
     * @param buf The tar entry's header buffer.
     * @return The computed checksum.
     */
    public static long computeCheckSum(final byte[] buf) {
        long sum = 0;

        for (int i = 0; i < buf.length; ++i) {
            sum += BYTE_MASK & buf[i];
        }

        return sum;
    }

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message