src/java.base/share/classes/java/util/zip/ZipEntry.java
changeset 57670 cffcc4c5a5ba
parent 50238 a9307f400f5a
child 59201 b24f4caa1411
equal deleted inserted replaced
57669:18f189e69b29 57670:cffcc4c5a5ba
     1 /*
     1 /*
     2  * Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   520      *         extra field data is greater than 0xFFFF bytes
   520      *         extra field data is greater than 0xFFFF bytes
   521      *
   521      *
   522      * @see #getExtra()
   522      * @see #getExtra()
   523      */
   523      */
   524     public void setExtra(byte[] extra) {
   524     public void setExtra(byte[] extra) {
   525         setExtra0(extra, false);
   525         setExtra0(extra, false, true);
   526     }
   526     }
   527 
   527 
   528     /**
   528     /**
   529      * Sets the optional extra field data for the entry.
   529      * Sets the optional extra field data for the entry.
   530      *
   530      *
   531      * @param extra
   531      * @param extra
   532      *        the extra field data bytes
   532      *        the extra field data bytes
   533      * @param doZIP64
   533      * @param doZIP64
   534      *        if true, set size and csize from ZIP64 fields if present
   534      *        if true, set size and csize from ZIP64 fields if present
   535      */
   535      * @param isLOC
   536     void setExtra0(byte[] extra, boolean doZIP64) {
   536      *        true if setting the extra field for a LOC, false if for
       
   537      *        a CEN
       
   538      */
       
   539     void setExtra0(byte[] extra, boolean doZIP64, boolean isLOC) {
   537         if (extra != null) {
   540         if (extra != null) {
   538             if (extra.length > 0xFFFF) {
   541             if (extra.length > 0xFFFF) {
   539                 throw new IllegalArgumentException("invalid extra field length");
   542                 throw new IllegalArgumentException("invalid extra field length");
   540             }
   543             }
   541             // extra fields are in "HeaderID(2)DataSize(2)Data... format
   544             // extra fields are in "HeaderID(2)DataSize(2)Data... format
   548                 if (off + sz > len)         // invalid data
   551                 if (off + sz > len)         // invalid data
   549                     break;
   552                     break;
   550                 switch (tag) {
   553                 switch (tag) {
   551                 case EXTID_ZIP64:
   554                 case EXTID_ZIP64:
   552                     if (doZIP64) {
   555                     if (doZIP64) {
   553                         // LOC extra zip64 entry MUST include BOTH original
   556                         if (isLOC) {
   554                         // and compressed file size fields.
   557                             // LOC extra zip64 entry MUST include BOTH original
   555                         // If invalid zip64 extra fields, simply skip. Even
   558                             // and compressed file size fields.
   556                         // it's rare, it's possible the entry size happens to
   559                             // If invalid zip64 extra fields, simply skip. Even
   557                         // be the magic value and it "accidently" has some
   560                             // it's rare, it's possible the entry size happens to
   558                         // bytes in extra match the id.
   561                             // be the magic value and it "accidently" has some
   559                         if (sz >= 16) {
   562                             // bytes in extra match the id.
   560                             size = get64(extra, off);
   563                             if (sz >= 16) {
   561                             csize = get64(extra, off + 8);
   564                                 size = get64(extra, off);
       
   565                                 csize = get64(extra, off + 8);
       
   566                             }
       
   567                         } else {
       
   568                             // CEN extra zip64
       
   569                             if (size == ZIP64_MAGICVAL) {
       
   570                                 if (off + 8 > len)  // invalid zip64 extra
       
   571                                     break;          // fields, just skip
       
   572                                 size = get64(extra, off);
       
   573                             }
       
   574                             if (csize == ZIP64_MAGICVAL) {
       
   575                                 if (off + 16 > len)  // invalid zip64 extra
       
   576                                     break;           // fields, just skip
       
   577                                 csize = get64(extra, off + 8);
       
   578                             }
   562                         }
   579                         }
   563                     }
   580                     }
   564                     break;
   581                     break;
   565                 case EXTID_NTFS:
   582                 case EXTID_NTFS:
   566                     if (sz < 32) // reserved  4 bytes + tag 2 bytes + size 2 bytes
   583                     if (sz < 32) // reserved  4 bytes + tag 2 bytes + size 2 bytes