Zip File error “header is corrupt” when i am adding exta field into header using java ZipEntry Class

天涯浪子 提交于 2019-12-08 11:40:32

问题


I set Content Type=text/xml in extra field of header while compressing. Below is my header.

PK�*�H27664.040.678.FI00091710.xmlContent Type=text/xml

It gives me error while decompressing validation fails "Header is corrupt".

When removing the extra field Content Type=text/xml everything works fine. I need to set header extra field as it s necessary for me. Can someone help me how I can proceed it without getting error with extra field.

Please help. Thanks in advance


回答1:


The extra field itself has an internal format that you are required to adhere to. From the PKWare appnote:

 4.5.1 In order to allow different programs and different types
   of information to be stored in the 'extra' field in .ZIP
   files, the following structure MUST be used for all
   programs storing data in this field:

       header1+data1 + header2+data2 . . .

   Each header should consist of:

       Header ID - 2 bytes
       Data Size - 2 bytes

   Note: all fields stored in Intel low-byte/high-byte order.

   The Header ID field indicates the type of data that is in
   the following data block.

   Header IDs of 0 thru 31 are reserved for use by PKWARE.
   The remaining IDs can be used by third party vendors for
   proprietary usage.

   4.5.2 The current Header ID mappings defined by PKWARE are:

      0x0001        Zip64 extended information extra field
      0x0007        AV Info
      0x0008        Reserved for extended language encoding data (PFS)
                    (see APPENDIX D)
      0x0009        OS/2
      0x000a        NTFS 
      0x000c        OpenVMS
      0x000d        UNIX
      0x000e        Reserved for file stream and fork descriptors
      0x000f        Patch Descriptor
      0x0014        PKCS#7 Store for X.509 Certificates
      0x0015        X.509 Certificate ID and Signature for 
                    individual file
      0x0016        X.509 Certificate ID for Central Directory
      0x0017        Strong Encryption Header
      0x0018        Record Management Controls
      0x0019        PKCS#7 Encryption Recipient Certificate List
      0x0065        IBM S/390 (Z390), AS/400 (I400) attributes 
                    - uncompressed
      0x0066        Reserved for IBM S/390 (Z390), AS/400 (I400) 
                    attributes - compressed
      0x4690        POSZIP 4690 (reserved) 

So you need to make up a header ID, and use that and a data size preceding your text.



来源:https://stackoverflow.com/questions/38478093/zip-file-error-header-is-corrupt-when-i-am-adding-exta-field-into-header-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!