VirtualBox

Changeset 34928 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 9, 2010 10:54:17 PM (14 years ago)
Author:
vboxsync
Message:

tarvfs.cpp: untested implementation of base-256 decoding.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/zip/tarvfs.cpp

    r34507 r34928  
    180180static int rtZipTarHdrFieldToNum(const char *pszField, size_t cchField, bool fOctalOnly, int64_t *pi64)
    181181{
    182     size_t const cchFieldOrg = cchField;
     182    unsigned char const *puchField   = (unsigned char const *)pszField;
     183    size_t const         cchFieldOrg = cchField;
    183184    if (   fOctalOnly
    184         || !(*(unsigned char *)pszField & 0x80))
     185        || !(*puchField & 0x80))
    185186    {
    186187        /*
    187188         * Skip leading spaces. Include zeros to save a few slower loops below.
    188189         */
    189         char ch;
    190         while (cchField > 0 && ((ch = *pszField) == ' '|| ch == '0'))
    191             cchField--, pszField++;
     190        unsigned char ch;
     191        while (cchField > 0 && ((ch = *puchField) == ' '|| ch == '0'))
     192            cchField--, puchField++;
    192193
    193194        /*
     
    197198        while (cchField > 0)
    198199        {
    199             unsigned char uDigit = *pszField - '0';
     200            unsigned char uDigit = *puchField - '0';
    200201            if (uDigit >= 8)
    201202                break;
     
    203204            i64 |= uDigit;
    204205
    205             pszField++;
     206            puchField++;
    206207            cchField--;
    207208        }
     
    213214        while (cchField > 0)
    214215        {
    215             ch = *pszField++;
     216            ch = *puchField++;
    216217            if (ch != 0 && ch != ' ')
    217218                return cchField < cchFieldOrg
     
    223224    else
    224225    {
    225         /** @todo implement base-256 encoded fields. */
    226         return VERR_TAR_BASE_256_NOT_SUPPORTED;
     226        /*
     227         * The first byte has the bit 7 set to indicate base-256, while bit 6
     228         * is the signed bit. Bits 5:0 are the most significant value bits.
     229         */
     230        int64_t i64 = !(0x40 & *puchField) ? 0 : -1;
     231        i64 = (i64 << 6) | (*puchField & 0x3f);
     232        cchField--;
     233        puchField++;
     234
     235        /*
     236         * The remaining bytes are used in full.
     237         */
     238        while (cchField-- > 0)
     239        {
     240            if (RT_UNLIKELY(i64 > INT64_MAX / 256))
     241                return VERR_TAR_NUM_VALUE_TOO_LARGE;
     242            if (RT_UNLIKELY(i64 < INT64_MIN / 256))
     243                return VERR_TAR_NUM_VALUE_TOO_LARGE;
     244            i64 = (i64 << 8) | *puchField++;
     245        }
     246        *pi64 = i64;
    227247    }
    228248
Note: See TracChangeset for help on using the changeset viewer.

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