~ubuntu-branches/ubuntu/trusty/xulrunner/trusty

« back to all changes in this revision

Viewing changes to modules/libjar/nsZipArchive.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2008-08-25 13:04:18 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20080825130418-ck1i2ms384tzb9m0
Tags: 1.8.1.16+nobinonly-0ubuntu1
* New upstream release (taken from upstream CVS), LP: #254618.
* Fix MFSA 2008-35, MFSA 2008-34, MFSA 2008-33, MFSA 2008-32, MFSA 2008-31,
  MFSA 2008-30, MFSA 2008-29, MFSA 2008-28, MFSA 2008-27, MFSA 2008-25,
  MFSA 2008-24, MFSA 2008-23, MFSA 2008-22, MFSA 2008-21, MFSA 2008-26 also
  known as CVE-2008-2933, CVE-2008-2785, CVE-2008-2811, CVE-2008-2810,
  CVE-2008-2809, CVE-2008-2808, CVE-2008-2807, CVE-2008-2806, CVE-2008-2805,
  CVE-2008-2803, CVE-2008-2802, CVE-2008-2801, CVE-2008-2800, CVE-2008-2798.
* Drop 89_bz419350_attachment_306066 patch, merged upstream.
* Bump Standards-Version to 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
992
992
    PRUint32 namelen = xtoint(central->filename_len);
993
993
    PRUint32 extralen = xtoint(central->extrafield_len);
994
994
    PRUint32 commentlen = xtoint(central->commentfield_len);
 
995
 
 
996
    //-- sanity check variable sizes and refuse to deal with
 
997
    //-- anything too big: it's likely a corrupt archive
 
998
    if (namelen > BR_BUF_SIZE || extralen > BR_BUF_SIZE || commentlen > 2*BR_BUF_SIZE) {
 
999
      status = ZIP_ERR_CORRUPT;
 
1000
      break;
 
1001
    }
 
1002
 
995
1003
#ifndef STANDALONE
996
1004
    // Arena allocate the nsZipItem
997
1005
    void *mem;
1010
1018
    item->headerOffset = xtolong(central->localhdr_offset);
1011
1019
    item->dataOffset = 0;
1012
1020
    item->hasDataOffset = PR_FALSE;
1013
 
    item->compression = (PRUint8)xtoint(central->method);
1014
 
#if defined(DEBUG)
1015
 
    /*
1016
 
     * Make sure our space optimization is non lossy.
1017
 
     */
1018
 
    PR_ASSERT(xtoint(central->method) == (PRUint16)item->compression);
1019
 
#endif
1020
1021
    item->size = xtolong(central->size);
1021
1022
    item->realsize = xtolong(central->orglen);
1022
1023
    item->crc32 = xtolong(central->crc32);
1026
1027
    item->time = xtoint(central->time);
1027
1028
    item->date = xtoint(central->date);
1028
1029
 
 
1030
    PRUint16 compression = xtoint(central->method);
 
1031
    item->compression = (compression < UNSUPPORTED) ? (PRUint8)compression
 
1032
                                                    : UNSUPPORTED;
 
1033
 
1029
1034
    pos += ZIPCENTRAL_SIZE;
1030
1035
 
1031
1036
    //-------------------------------------------------------
1043
1048
    }
1044
1049
#else
1045
1050
    item->name = new char[namelen + 1];
1046
 
#endif
1047
1051
    if (!item->name)
1048
1052
    {
1049
1053
      status = ZIP_ERR_MEMORY;
1050
1054
      delete item;
1051
1055
      break;
1052
1056
    }
 
1057
#endif
1053
1058
 
1054
1059
    PRUint32 leftover = (PRUint32)(bufsize - pos);
1055
1060
    if (leftover < namelen)
1088
1093
      memcpy(buf, buf+pos, leftover);
1089
1094
      bufsize = leftover + PR_Read(aFd, buf+leftover, bufsize-leftover);
1090
1095
      pos = 0;
 
1096
 
 
1097
      //-- make sure we were able to read enough
 
1098
      if ((PRUint32)bufsize < (extralen + commentlen + sizeof(PRUint32)))
 
1099
      {
 
1100
        status = ZIP_ERR_CORRUPT;
 
1101
        break;
 
1102
      }
1091
1103
    }
1092
1104
    //-- set position to start of next ZipCentral record
1093
1105
    pos += extralen + commentlen;
1094
1106
 
 
1107
    // verify we're at an expected structure in the file
1095
1108
    PRUint32 sig = xtolong(buf+pos);
1096
1109
    if (sig != CENTRALSIG)
1097
1110
    {
1371
1384
{
1372
1385
  // we still use the fields of mZs, we just use memcpy rather than inflate
1373
1386
 
1374
 
  if (mCurPos + aCount > mItem->realsize)
1375
 
    aCount = (mItem->realsize - mCurPos);
 
1387
  if (mCurPos + aCount > mItem->size)
 
1388
    aCount = (mItem->size - mCurPos);
1376
1389
 
1377
1390
  PR_ASSERT(mFd);
1378
1391
  PRInt32 bytesRead = PR_Read(mFd, aBuf, aCount);
1380
1393
    return ZIP_ERR_DISK;
1381
1394
 
1382
1395
  mCurPos += bytesRead;
1383
 
  
 
1396
  if (bytesRead != aCount)
 
1397
    // either file was truncated or archive lied about size
 
1398
    return ZIP_ERR_CORRUPT;
 
1399
 
1384
1400
  *aBytesRead = bytesRead;
1385
1401
 
1386
1402
  return ZIP_OK;