< prev index next >

src/java.base/share/native/libzip/zip_util.c

Print this page




 659 
 660     /* Iterate through the entries in the central directory */
 661     for (i = 0, cp = cenbuf; cp <= cenend - CENHDR; i++, cp += CENSIZE(cp)) {
 662         /* Following are unsigned 16-bit */
 663         jint method, nlen;
 664         unsigned int hsh;
 665 
 666         if (i >= total) {
 667             /* This will only happen if the zip file has an incorrect
 668              * ENDTOT field, which usually means it contains more than
 669              * 65535 entries. */
 670             cenpos = readCEN(zip, countCENHeaders(cenbuf, cenend));
 671             goto Finally;
 672         }
 673 
 674         method = CENHOW(cp);
 675         nlen   = CENNAM(cp);
 676 
 677         if (!CENSIG_AT(cp))
 678             ZIP_FORMAT_ERROR("invalid CEN header (bad signature)");
 679         if (CENFLG(cp) & 1)
 680             ZIP_FORMAT_ERROR("invalid CEN header (encrypted entry)");
 681         if (method != STORED && method != DEFLATED)
 682             ZIP_FORMAT_ERROR("invalid CEN header (bad compression method)");
 683         if (cp + CENHDR + nlen > cenend)
 684             ZIP_FORMAT_ERROR("invalid CEN header (bad header size)");
 685 
 686         /* if the entry is metadata add it to our metadata names */
 687         if (isMetaName((char *)cp+CENHDR, nlen))
 688             if (addMetaName(zip, (char *)cp+CENHDR, nlen) != 0)
 689                 goto Catch;
 690 
 691         /* Record the CEN offset and the name hash in our hash cell. */
 692         entries[i].cenpos = cenpos + (cp - cenbuf);
 693         entries[i].hash = hashN((char *)cp+CENHDR, nlen);
 694 
 695         /* Add the entry to the hash table */
 696         hsh = entries[i].hash % tablelen;
 697         entries[i].next = table[hsh];
 698         table[hsh] = i;
 699     }
 700     if (cp != cenend)


 981     ze->name    = NULL;
 982     ze->extra   = NULL;
 983     ze->comment = NULL;
 984 
 985 #ifdef USE_MMAP
 986     if (zip->usemmap) {
 987         cen = (char*) zip->maddr + zc->cenpos - zip->offset;
 988     } else
 989 #endif
 990     {
 991         if (accessHint == ACCESS_RANDOM)
 992             cen = readCENHeader(zip, zc->cenpos, AMPLE_CEN_HEADER_SIZE);
 993         else
 994             cen = sequentialAccessReadCENHeader(zip, zc->cenpos);
 995         if (cen == NULL) goto Catch;
 996     }
 997 
 998     nlen      = CENNAM(cen);
 999     elen      = CENEXT(cen);
1000     clen      = CENCOM(cen);

1001     ze->time  = CENTIM(cen);
1002     ze->size  = CENLEN(cen);
1003     ze->csize = (CENHOW(cen) == STORED) ? 0 : CENSIZ(cen);
1004     ze->crc   = CENCRC(cen);
1005     locoff    = CENOFF(cen);
1006     ze->pos   = -(zip->locpos + locoff);
1007     ze->flag  = CENFLG(cen);
1008 
1009     if ((ze->name = malloc(nlen + 1)) == NULL) goto Catch;
1010     memcpy(ze->name, cen + CENHDR, nlen);
1011     ze->name[nlen] = '\0';
1012     ze->nlen = nlen;
1013     if (elen > 0) {
1014         char *extra = cen + CENHDR + nlen;
1015 
1016         /* This entry has "extra" data */
1017         if ((ze->extra = malloc(elen + 2)) == NULL) goto Catch;
1018         ze->extra[0] = (unsigned char) elen;
1019         ze->extra[1] = (unsigned char) (elen >> 8);
1020         memcpy(ze->extra+2, extra, elen);
1021         if (ze->csize == ZIP64_MAGICVAL || ze->size == ZIP64_MAGICVAL ||
1022             locoff == ZIP64_MAGICVAL) {
1023             jint off = 0;




 659 
 660     /* Iterate through the entries in the central directory */
 661     for (i = 0, cp = cenbuf; cp <= cenend - CENHDR; i++, cp += CENSIZE(cp)) {
 662         /* Following are unsigned 16-bit */
 663         jint method, nlen;
 664         unsigned int hsh;
 665 
 666         if (i >= total) {
 667             /* This will only happen if the zip file has an incorrect
 668              * ENDTOT field, which usually means it contains more than
 669              * 65535 entries. */
 670             cenpos = readCEN(zip, countCENHeaders(cenbuf, cenend));
 671             goto Finally;
 672         }
 673 
 674         method = CENHOW(cp);
 675         nlen   = CENNAM(cp);
 676 
 677         if (!CENSIG_AT(cp))
 678             ZIP_FORMAT_ERROR("invalid CEN header (bad signature)");


 679         if (method != STORED && method != DEFLATED)
 680             ZIP_FORMAT_ERROR("invalid CEN header (bad compression method)");
 681         if (cp + CENHDR + nlen > cenend)
 682             ZIP_FORMAT_ERROR("invalid CEN header (bad header size)");
 683 
 684         /* if the entry is metadata add it to our metadata names */
 685         if (isMetaName((char *)cp+CENHDR, nlen))
 686             if (addMetaName(zip, (char *)cp+CENHDR, nlen) != 0)
 687                 goto Catch;
 688 
 689         /* Record the CEN offset and the name hash in our hash cell. */
 690         entries[i].cenpos = cenpos + (cp - cenbuf);
 691         entries[i].hash = hashN((char *)cp+CENHDR, nlen);
 692 
 693         /* Add the entry to the hash table */
 694         hsh = entries[i].hash % tablelen;
 695         entries[i].next = table[hsh];
 696         table[hsh] = i;
 697     }
 698     if (cp != cenend)


 979     ze->name    = NULL;
 980     ze->extra   = NULL;
 981     ze->comment = NULL;
 982 
 983 #ifdef USE_MMAP
 984     if (zip->usemmap) {
 985         cen = (char*) zip->maddr + zc->cenpos - zip->offset;
 986     } else
 987 #endif
 988     {
 989         if (accessHint == ACCESS_RANDOM)
 990             cen = readCENHeader(zip, zc->cenpos, AMPLE_CEN_HEADER_SIZE);
 991         else
 992             cen = sequentialAccessReadCENHeader(zip, zc->cenpos);
 993         if (cen == NULL) goto Catch;
 994     }
 995 
 996     nlen      = CENNAM(cen);
 997     elen      = CENEXT(cen);
 998     clen      = CENCOM(cen);
 999     ze->method = CENHOW(cen);
1000     ze->time  = CENTIM(cen);
1001     ze->size  = CENLEN(cen);
1002     ze->csize = CENSIZ(cen);
1003     ze->crc   = CENCRC(cen);
1004     locoff    = CENOFF(cen);
1005     ze->pos   = -(zip->locpos + locoff);
1006     ze->flag  = CENFLG(cen);
1007 
1008     if ((ze->name = malloc(nlen + 1)) == NULL) goto Catch;
1009     memcpy(ze->name, cen + CENHDR, nlen);
1010     ze->name[nlen] = '\0';
1011     ze->nlen = nlen;
1012     if (elen > 0) {
1013         char *extra = cen + CENHDR + nlen;
1014 
1015         /* This entry has "extra" data */
1016         if ((ze->extra = malloc(elen + 2)) == NULL) goto Catch;
1017         ze->extra[0] = (unsigned char) elen;
1018         ze->extra[1] = (unsigned char) (elen >> 8);
1019         memcpy(ze->extra+2, extra, elen);
1020         if (ze->csize == ZIP64_MAGICVAL || ze->size == ZIP64_MAGICVAL ||
1021             locoff == ZIP64_MAGICVAL) {
1022             jint off = 0;


< prev index next >