VirtualBox

Changeset 34060 in vbox for trunk


Ignore:
Timestamp:
Nov 14, 2010 11:15:04 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
67742
Message:

some tar bits

Location:
trunk/src/VBox/Runtime/common/zip
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/zip/tar.h

    r34049 r34060  
    105105
    106106/**
     107 * The GNU header.
     108 */
     109typedef struct RTZIPTARHDRGNU
     110{
     111    char    name[100];
     112    char    mode[8];
     113    char    uid[8];
     114    char    gid[8];
     115    char    size[12];
     116    char    mtime[12];
     117    char    chksum[8];
     118    char    typeflag;
     119    char    linkname[100];
     120    char    magic[8];
     121    char    uname[32];
     122    char    gname[32];
     123    char    devmajor[8];
     124    char    devminor[8];
     125    char    atime[12];
     126    char    ctime[12];
     127    char    offset[12];
     128    char    longnames[4];
     129    char    unused[1];
     130    struct
     131    {
     132        char offset[12];
     133        char numbytes[12];
     134    }       sparse[4];
     135    char    isextended;
     136    char    realsize[12];
     137    char    unused2[17];
     138} RTZIPTARHDRGNU;
     139AssertCompileSize(RTZIPTARHDRGNU, 512);
     140AssertCompileMemberOffset(RTZIPTARHDRGNU, name,        0);
     141AssertCompileMemberOffset(RTZIPTARHDRGNU, mode,      100);
     142AssertCompileMemberOffset(RTZIPTARHDRGNU, uid,       108);
     143AssertCompileMemberOffset(RTZIPTARHDRGNU, gid,       116);
     144AssertCompileMemberOffset(RTZIPTARHDRGNU, size,      124);
     145AssertCompileMemberOffset(RTZIPTARHDRGNU, mtime,     136);
     146AssertCompileMemberOffset(RTZIPTARHDRGNU, chksum,    148);
     147AssertCompileMemberOffset(RTZIPTARHDRGNU, typeflag,  156);
     148AssertCompileMemberOffset(RTZIPTARHDRGNU, linkname,  157);
     149AssertCompileMemberOffset(RTZIPTARHDRGNU, magic,     257);
     150AssertCompileMemberOffset(RTZIPTARHDRGNU, uname,     265);
     151AssertCompileMemberOffset(RTZIPTARHDRGNU, gname,     297);
     152AssertCompileMemberOffset(RTZIPTARHDRGNU, devmajor,  329);
     153AssertCompileMemberOffset(RTZIPTARHDRGNU, devminor,  337);
     154AssertCompileMemberOffset(RTZIPTARHDRGNU, atime,     345);
     155AssertCompileMemberOffset(RTZIPTARHDRGNU, ctime,     357);
     156AssertCompileMemberOffset(RTZIPTARHDRGNU, offset,    369);
     157AssertCompileMemberOffset(RTZIPTARHDRGNU, longnames, 381);
     158AssertCompileMemberOffset(RTZIPTARHDRGNU, unused,    385);
     159AssertCompileMemberOffset(RTZIPTARHDRGNU, sparse,    386);
     160AssertCompileMemberOffset(RTZIPTARHDRGNU, isextended,482);
     161AssertCompileMemberOffset(RTZIPTARHDRGNU, realsize,  483);
     162AssertCompileMemberOffset(RTZIPTARHDRGNU, unused2,   495);
     163
     164
     165/**
    107166 * Tar header union.
    108167 */
     
    110169{
    111170    /** Byte view. */
    112     char            ab[512];
     171    char                ab[512];
    113172    /** The standard header. */
    114     RTZIPTARHDRPOSIX Posix;
     173    RTZIPTARHDRPOSIX    Posix;
     174    /** The GNU header. */
     175    RTZIPTARHDRGNU      Gnu;
    115176} RTZIPTARHDR;
    116177AssertCompileSize(RTZIPTARHDR, 512);
     
    120181typedef RTZIPTARHDR const *PCRTZIPTARHDR;
    121182
     183
     184/**
     185 * Tar header type.
     186 */
     187typedef enum RTZIPTARTYPE
     188{
     189    /** Invalid type value. */
     190    RTZIPTARTYPE_INVALID = 0,
     191    /** Posix header.  */
     192    RTZIPTARTYPE_POSIX,
     193    /** The old GNU header, has layout conflicting with posix. */
     194    RTZIPTARTYPE_GNU,
     195    /** Ancient tar header which does not use anything beyond the magic. */
     196    RTZIPTARTYPE_ANCIENT,
     197    /** End of the valid type values (this is not valid).  */
     198    RTZIPTARTYPE_END,
     199    /** The usual type blow up.  */
     200    RTZIPTARTYPE_32BIT_HACK = 0x7fffffff
     201} RTZIPTARTYPE;
     202typedef RTZIPTARTYPE *PRTZIPTARTYPE;
     203
     204
    122205#endif
    123206
  • trunk/src/VBox/Runtime/common/zip/tarvfs.cpp

    r34055 r34060  
    306306 * @returns VINF_SUCCESS if valid, appropriate VERR_TAR_XXX if not.
    307307 * @param   pTar                The TAR header.
    308  */
    309 static int rtZipTarHdrValidate(PCRTZIPTARHDR pTar)
     308 * @param   penmType            Where to return the type of header on success.
     309 */
     310static int rtZipTarHdrValidate(PCRTZIPTARHDR pTar, PRTZIPTARTYPE penmType)
    310311{
    311312    /*
     
    325326        return VERR_TAR_BAD_CHKSUM_FIELD;
    326327    if (   i32ChkSum          != i64HdrChkSum
    327         && i32ChkSumSignedAlt != i64HdrChkSum) /** @todo check this */
     328        && i32ChkSumSignedAlt != i64HdrChkSum) /** @todo test this */
    328329        return VERR_TAR_CHKSUM_MISMATCH;
    329330
    330331    /*
     332     * Detect the tar type.
     333     */
     334    RTZIPTARTYPE enmType;
     335    if (   pTar->Posix.magic[0] == 'u'
     336        && pTar->Posix.magic[1] == 's'
     337        && pTar->Posix.magic[2] == 't'
     338        && pTar->Posix.magic[3] == 'a'
     339        && pTar->Posix.magic[4] == 'r')
     340    {
     341        if (   pTar->Posix.magic[5]   == '\0'
     342            && pTar->Posix.version[0] == '0'
     343            && pTar->Posix.version[1] == '0')
     344            enmType = RTZIPTARTYPE_POSIX;
     345        else if (   pTar->Posix.magic[5]   == ' '
     346                && pTar->Posix.version[0] == ' '
     347                && pTar->Posix.version[1] == '\0')
     348            enmType = RTZIPTARTYPE_GNU;
     349        else
     350            return VERR_TAR_NOT_USTAR_V00;
     351    }
     352    else
     353        enmType = RTZIPTARTYPE_ANCIENT;
     354    *penmType = enmType;
     355
     356    /*
    331357     * Perform some basic checks.
    332358     */
    333     if (!rtZipTarHdrIsUstar(pTar))
    334     {
    335 RTAssertMsg2("%.6s%c%c\n", pTar->Posix.magic, pTar->Posix.version[0], pTar->Posix.version[1]);
    336 RTAssertMsg2("%.8Rhxs\n", pTar->Posix.magic);
    337         return VERR_TAR_NOT_USTAR_V00;
    338     }
    339 
     359    /** @todo more/less? */
    340360    switch (pTar->Posix.typeflag)
    341361    {
     
    352372                return VERR_TAR_EMPTY_NAME;
    353373
     374            /** @todo People claim some (older and newer buggy) tar stores dirs as regular files with a trailing slash. */
    354375            const char *pchEnd = RTStrEnd(&pTar->Posix.name[0], sizeof(pTar->Posix.name));
    355376            pchEnd = pchEnd ? pchEnd - 1 : &pTar->Posix.name[sizeof(pTar->Posix.name) - 1];
     
    379400            return VERR_TAR_UNSUPPORTED_GNU_HDR_TYPE;
    380401    }
     402
    381403
    382404    return VINF_SUCCESS;
     
    9821004     * We pick up the start of the zero headers here in the failure path.
    9831005     */
    984     rc = rtZipTarHdrValidate(&Hdr);
     1006    RTZIPTARTYPE enmTarType;
     1007    rc = rtZipTarHdrValidate(&Hdr, &enmTarType);
    9851008    if (RT_FAILURE_NP(rc))
    9861009    {
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette