idnits 2.17.00 (12 Aug 2021) /tmp/idnits59079/draft-deutsch-gzip-spec-02.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- ** Cannot find the required boilerplate sections (Copyright, IPR, etc.) in this document. Expected boilerplate is as follows today (2022-05-20) according to https://trustee.ietf.org/license-info : IETF Trust Legal Provisions of 28-dec-2009, Section 6.a: This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79. IETF Trust Legal Provisions of 28-dec-2009, Section 6.b(i), paragraph 2: Copyright (c) 2022 IETF Trust and the persons identified as the document authors. All rights reserved. IETF Trust Legal Provisions of 28-dec-2009, Section 6.b(i), paragraph 3: This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- ** Missing expiration date. The document expiration date should appear on the first and last page. ** The document seems to lack a 1id_guidelines paragraph about Internet-Drafts being working documents. ** The document seems to lack a 1id_guidelines paragraph about 6 months document validity -- however, there's a paragraph with a matching beginning. Boilerplate error? ** The document seems to lack a 1id_guidelines paragraph about the list of current Internet-Drafts. ** The document seems to lack a 1id_guidelines paragraph about the list of Shadow Directories. == No 'Intended status' indicated for this document; assuming Proposed Standard == The page length should not exceed 58 lines per page, but there was 11 longer pages, the longest (page 2) being 59 lines Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The document seems to lack an IANA Considerations section. (See Section 2.2 of https://www.ietf.org/id-info/checklist for how to handle the case when there are no actions for IANA.) ** The document seems to lack separate sections for Informative/Normative References. All references will be assumed normative when checking for downward references. == There are 2 instances of lines with non-RFC6890-compliant IPv4 addresses in the document. If these are example addresses, they should be changed. Miscellaneous warnings: ---------------------------------------------------------------------------- -- The document seems to lack a disclaimer for pre-RFC5378 work, but may have content which was first submitted before 10 November 2008. If you have contacted all the original authors and they are all willing to grant the BCP78 rights to the IETF Trust, then this is fine, and you can ignore this comment. If not, you may need to add the pre-RFC5378 disclaimer. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- The document date (11 Mar 1996) is 9566 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Missing Reference: '256' is mentioned on line 538, but not defined == Unused Reference: '1' is defined on line 427, but no explicit reference was found in the text == Unused Reference: '2' is defined on line 433, but no explicit reference was found in the text == Unused Reference: '3' is defined on line 435, but no explicit reference was found in the text == Unused Reference: '4' is defined on line 437, but no explicit reference was found in the text == Unused Reference: '5' is defined on line 440, but no explicit reference was found in the text == Unused Reference: '6' is defined on line 443, but no explicit reference was found in the text == Unused Reference: '7' is defined on line 446, but no explicit reference was found in the text == Unused Reference: '8' is defined on line 449, but no explicit reference was found in the text -- Possible downref: Non-RFC (?) normative reference: ref. '1' -- Possible downref: Non-RFC (?) normative reference: ref. '2' -- Possible downref: Non-RFC (?) normative reference: ref. '3' -- Possible downref: Non-RFC (?) normative reference: ref. '4' -- Possible downref: Non-RFC (?) normative reference: ref. '5' -- Possible downref: Non-RFC (?) normative reference: ref. '6' -- Possible downref: Non-RFC (?) normative reference: ref. '7' -- Possible downref: Non-RFC (?) normative reference: ref. '8' Summary: 8 errors (**), 0 flaws (~~), 12 warnings (==), 11 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 INTERNET-DRAFT L. Peter Deutsch 3 GZIP 4.3 Aladdin Enterprises 4 Expires: 16 Sep 1996 11 Mar 1996 6 GZIP file format specification version 4.3 8 File draft-deutsch-gzip-spec-02.txt 10 Status of this Memo 12 This document is an Internet-Draft. Internet-Drafts are working 13 documents of the Internet Engineering Task Force (IETF), its areas, 14 and its working groups. Note that other groups may also distribute 15 working documents as Internet-Drafts. 17 Internet-Drafts are draft documents valid for a maximum of six months 18 and may be updated, replaced, or obsoleted by other documents at any 19 time. It is inappropriate to use Internet- Drafts as reference 20 material or to cite them other than as ``work in progress.'' 22 To learn the current status of any Internet-Draft, please check the 23 ``1id-abstracts.txt'' listing contained in the Internet- Drafts 24 Shadow Directories on ftp.is.co.za (Africa), nic.nordu.net (Europe), 25 munnari.oz.au (Pacific Rim), ds.internic.net (US East Coast), or 26 ftp.isi.edu (US West Coast). 28 Distribution of this memo is unlimited. 30 Notices 32 Copyright (c) 1996 L. Peter Deutsch 34 Permission is granted to copy and distribute this document for any 35 purpose and without charge, including translations into other 36 languages and incorporation into compilations, provided that it is 37 copied as a whole (including the copyright notice and this notice) 38 and with no changes. 40 Deutsch [Page 1] 41 Abstract 43 This specification defines a lossless compressed data format that is 44 compatible with the widely used GZIP utility. The format includes a 45 cyclic redundancy check value for detecting data corruption. The 46 format presently uses the DEFLATE method of compression but can be 47 easily extended to use other compression methods. The format can be 48 implemented readily in a manner not covered by patents. 50 Table of Contents 52 1. Introduction ................................................... 2 53 1.1. Purpose ................................................... 2 54 1.2. Intended audience ......................................... 3 55 1.3. Scope ..................................................... 3 56 1.4. Compliance ................................................ 3 57 1.5. Definitions of terms and conventions used ................. 3 58 1.6. Changes from previous versions ............................ 3 59 2. Detailed specification ......................................... 4 60 2.1. Overall conventions ....................................... 4 61 2.2. File format ............................................... 5 62 2.3. Member format ............................................. 5 63 2.3.1. Member header and trailer ........................... 5 64 * 2.3.1.1. Extra field ...................... 8 65 * 2.3.1.2. Compliance ....................... 9 66 3. References .................................................. 9 67 4. Security considerations .................................... 10 68 5. Acknowledgements ........................................... 10 69 6. Author's address ........................................... 10 70 7. Appendix: Jean-loup Gailly's gzip utility .................. 11 71 8. Appendix: Sample CRC Code .................................. 11 73 1. Introduction 75 1.1. Purpose 77 The purpose of this specification is to define a lossless 78 compressed data format that: 80 * Is independent of CPU type, operating system, file system, 81 and character set, and hence can be used for interchange; 82 * Can compress or decompress a data stream (as opposed to a 83 randomly accessible file) to produce another data stream, 84 using only an a priori bounded amount of intermediate 85 storage, and hence can be used in data communications or 86 similar structures such as Unix filters; 87 * Compresses data with efficiency comparable to the best 88 currently available general-purpose compression methods, and 89 in particular considerably better than the 'compress' 90 program; 91 * Can be implemented readily in a manner not covered by 92 patents, and hence can be practiced freely; 94 Deutsch [Page 2] 95 * Is compatible with the file format produced by the current 96 widely used gzip utility, in that conforming decompressors 97 will be able to read data produced by the existing gzip 98 compressor. 100 The data format defined by this specification does not attempt to: 102 * Provide random access to compressed data; 103 * Compress specialized data (e.g., raster graphics) as well as 104 the best currently available specialized algorithms. 106 1.2. Intended audience 108 This specification is intended for use by implementors of software 109 to compress data into gzip format and/or decompress data from gzip 110 format. 112 The text of the specification assumes a basic background in 113 programming at the level of bits and other primitive data 114 representations. 116 1.3. Scope 118 The specification specifies a compression method and a file format 119 (the latter assuming only that a file can store a sequence of 120 arbitrary bytes). It does not specify any particular interface to 121 a file system or anything about character sets or encodings 122 (except for file names and comments, which are optional). 124 1.4. Compliance 126 Unless otherwise indicated below, a compliant decompressor must be 127 able to accept and decompress any file that conforms to all the 128 specifications presented here; a compliant compressor must produce 129 files that conform to all the specifications presented here. The 130 material in the appendices is not part of the specification per se 131 and is not relevant to compliance. 133 1.5. Definitions of terms and conventions used 135 byte: 8 bits stored or transmitted as a unit (same as an octet). 136 (For this specification, a byte is exactly 8 bits, even on 137 machines which store a character on a number of bits different 138 from 8.) See below for the numbering of bits within a byte. 140 1.6. Changes from previous versions 142 There have been no technical changes to the gzip format since 143 version 4.1 of this specification. In version 4.2, some 144 terminology was changed, and the sample CRC code was rewritten for 145 clarity and to eliminate the requirement for the caller to do pre- 146 and post-conditioning. Version 4.3 is a conversion of the 148 Deutsch [Page 3] 149 specification to Internet Draft style. 151 2. Detailed specification 153 2.1. Overall conventions 155 In the diagrams below, a box like this: 157 +---+ 158 | | <-- the vertical bars might be missing 159 +---+ 161 represents one byte; a box like this: 163 +==============+ 164 | | 165 +==============+ 167 represents a variable number of bytes. 169 Bytes stored within a computer do not have a 'bit order', since 170 they are always treated as a unit. However, a byte considered as 171 an integer between 0 and 255 does have a most- and least- 172 significant bit, and since we write numbers with the most- 173 significant digit on the left, we also write bytes with the most- 174 significant bit on the left. In the diagrams below, we number the 175 bits of a byte so that bit 0 is the least-significant bit, i.e., 176 the bits are numbered: 178 +--------+ 179 |76543210| 180 +--------+ 182 This document does not address the issue of the order in which 183 bits of a byte are transmitted on a bit-sequential medium, since 184 the data format described here is byte- rather than bit-oriented. 186 Within a computer, a number may occupy multiple bytes. All 187 multi-byte numbers in the format described here are stored with 188 the least-significant byte first (at the lower memory address). 189 For example, the decimal number 520 is stored as: 191 0 1 192 +--------+--------+ 193 |00001000|00000010| 194 +--------+--------+ 195 ^ ^ 196 | | 197 | + more significant byte = 2 x 256 198 + less significant byte = 8 200 Deutsch [Page 4] 201 2.2. File format 203 A gzip file consists of a series of "members" (compressed data 204 sets). The format of each member is specified in the following 205 section. The members simply appear one after another in the file, 206 with no additional information before, between, or after them. 208 2.3. Member format 210 Each member has the following structure: 212 +---+---+---+---+---+---+---+---+---+---+ 213 |ID1|ID2|CM |FLG| MTIME |XFL|OS | (more-->) 214 +---+---+---+---+---+---+---+---+---+---+ 216 (if FLG.FEXTRA set) 218 +---+---+=================================+ 219 | XLEN |...XLEN bytes of 'extra field'...| (more-->) 220 +---+---+=================================+ 222 (if FLG.FNAME set) 224 +=========================================+ 225 |...original file name, zero-terminated...| (more-->) 226 +=========================================+ 228 (if FLG.FCOMMENT set) 230 +===================================+ 231 |...file comment, zero-terminated...| (more-->) 232 +===================================+ 234 (if FLG.FHCRC set) 236 +---+---+ 237 | CRC16 | 238 +---+---+ 240 +=======================+ 241 |...compressed blocks...| (more-->) 242 +=======================+ 244 0 1 2 3 4 5 6 7 245 +---+---+---+---+---+---+---+---+ 246 | CRC32 | ISIZE | 247 +---+---+---+---+---+---+---+---+ 249 2.3.1. Member header and trailer 251 Deutsch [Page 5] 252 ID1 (IDentification 1) 253 ID2 (IDentification 2) 254 These have the fixed values ID1 = 31 (0x1f, \037), ID2 = 139 255 (0x8b, \213), to identify the file as being in gzip format. 257 CM (Compression Method) 258 This identifies the compression method used in the file. CM 259 = 0-7 are reserved. CM = 8 denotes the 'deflate' 260 compression method, which is the one customarily used by 261 gzip and which is documented elsewhere. 263 FLG (FLaGs) 264 This flag byte is divided into individual bits as follows: 266 bit 0 FTEXT 267 bit 1 FHCRC 268 bit 2 FEXTRA 269 bit 3 FNAME 270 bit 4 FCOMMENT 271 bit 5 reserved 272 bit 6 reserved 273 bit 7 reserved 275 If FTEXT is set, the file is probably ASCII text. This is 276 an optional indication, which the compressor may set by 277 checking a small amount of the input data to see whether any 278 non-ASCII characters are present. In case of doubt, FTEXT 279 is cleared, indicating binary data. For systems which have 280 different file formats for ascii text and binary data, the 281 decompressor can use FTEXT to choose the appropriate format. 282 We deliberately do not specify the algorithm used to set 283 this bit, since a compressor always has the option of 284 leaving it cleared and a decompressor always has the option 285 of ignoring it and letting some other program handle issues 286 of data conversion. 288 If FHCRC is set, a CRC16 for the gzip header is present, 289 immediately before the compressed data. The CRC16 consists 290 of the two least significant bytes of the CRC32 for all 291 bytes of the gzip header up to and not including the CRC16. 292 [The FHCRC bit was never set by versions of gzip up to 293 1.2.4, even though it was documented with a different 294 meaning in gzip 1.2.4.] 296 If FEXTRA is set, optional extra fields are present, as 297 described in a following section. 299 If FNAME is set, an original file name is present, 300 terminated by a zero byte. The name must consist of ISO 301 8859-1 (LATIN-1) characters; on operating systems using 302 EBCDIC or any other character set for file names, the name 303 must be translated to the ISO LATIN-1 character set. This 305 Deutsch [Page 6] 306 is the original name of the file being compressed, with any 307 directory components removed, and, if the file being 308 compressed is on a file system with case insensitive names, 309 forced to lower case. There is no original file name if the 310 data was compressed from a source other than a named file; 311 for example, if the source was stdin on a Unix system, there 312 is no file name. 314 If FCOMMENT is set, a zero-terminated file comment is 315 present. This comment is not interpreted; it is only 316 intended for human consumption. The comment must consist of 317 ISO 8859-1 (LATIN-1) characters. Line breaks should be 318 denoted by a single line feed character (10 decimal). 320 Reserved FLG bits must be zero. 322 MTIME (Modification TIME) 323 This gives the most recent modification time of the original 324 file being compressed. The time is in Unix format, i.e., 325 seconds since 00:00:00 GMT, Jan. 1, 1970. (Note that this 326 may cause problems for MS-DOS and other systems that use 327 local rather than Universal time.) If the compressed data 328 did not come from a file, MTIME is set to the time at which 329 compression started. MTIME = 0 means no time stamp is 330 available. 332 XFL (eXtra FLags) 333 These flags are available for use by specific compression 334 methods. The 'deflate' method (CM = 8) sets these flags as 335 follows: 337 XFL = 2 - compressor used maximum compression, 338 slowest algorithm 339 XFL = 4 - compressor used fastest algorithm 341 OS (Operating System) 342 This identifies the type of file system on which compression 343 took place. This may be useful in determining end-of-line 344 convention for text files. The currently defined values are 345 as follows: 347 Deutsch [Page 7] 348 0 - FAT filesystem (MS-DOS, OS/2, NT/Win32) 349 1 - Amiga 350 2 - VMS (or OpenVMS) 351 3 - Unix 352 4 - VM/CMS 353 5 - Atari TOS 354 6 - HPFS filesystem (OS/2, NT) 355 7 - Macintosh 356 8 - Z-System 357 9 - CP/M 358 10 - TOPS-20 359 11 - NTFS filesystem (NT) 360 12 - QDOS 361 13 - Acorn RISCOS 362 255 - unknown 364 XLEN (eXtra LENgth) 365 If FLG.FEXTRA is set, this gives the length of the optional 366 extra field. See below for details. 368 CRC32 (CRC-32) 369 This contains a Cyclic Redundancy Check value of the 370 uncompressed data computed according to CRC-32 algorithm 371 used in the ISO 3309 standard and in section 8.1.1.6.2 of 372 ITU-T recommendation V.42. (See http://www.iso.ch for 373 ordering ISO documents. See gopher://info.itu.ch for an 374 online version of ITU-T V.42.) 376 ISIZE (Input SIZE) 377 This contains the size of the original (uncompressed) input 378 data modulo 2^32. 380 2.3.1.1. Extra field 382 If the FLG.FEXTRA bit is set, an "extra field" is present in 383 the header, with total length XLEN bytes. It consists of a 384 series of subfields, each of the form: 386 +---+---+---+---+==================================+ 387 |SI1|SI2| LEN |... LEN bytes of subfield data ...| 388 +---+---+---+---+==================================+ 390 SI1 and SI2 provide a subfield ID, typically two ASCII letters 391 with some mnemonic value. Jean-loup Gailly 392 is maintaining a registry of subfield 393 IDs; please send him any subfield ID you wish to use. Subfield 394 IDs with SI2 = 0 are reserved for future use. The following 395 IDs are currently defined: 397 SI1 SI2 Data 398 ---------- ---------- ---- 399 0x41 ('A') 0x70 ('P') Apollo file type information 401 Deutsch [Page 8] 402 LEN gives the length of the subfield data, excluding the 4 403 initial bytes. 405 2.3.1.2. Compliance 407 A compliant compressor must produce files with correct ID1, 408 ID2, CM, CRC32, and ISIZE, but may set all the other fields in 409 the fixed-length part of the header to default values (255 for 410 OS, 0 for all others). The compressor must set all reserved 411 bits to zero. 413 A compliant decompressor must check ID1, ID2, and CM, and 414 provide an error indication if any of these have incorrect 415 values. It must examine FEXTRA/XLEN, FNAME, FCOMMENT and FHCRC 416 at least so it can skip over the optional fields if they are 417 present. It need not examine any other part of the header or 418 trailer; in particular, a decompressor may ignore FTEXT and OS 419 and always produce binary output, and still be compliant. A 420 compliant decompressor must give an error indication if any 421 reserved bit is non-zero, since such a bit could indicate the 422 presence of a new field that would cause subsequent data to be 423 interpreted incorrectly. 425 3. References 427 [1] "Information Processing - 8-bit single-byte coded graphic 428 character sets - Part 1: Latin alphabet No.1" (ISO 8859-1:1987). 429 The ISO 8859-1 (Latin-1) character set is a superset of 7-bit 430 ASCII. Files defining this character set may be obtained from 431 ftp.uu.net:/graphics/png/documents/iso_8859-1.* 433 [2] ISO 3309 435 [3] ITU-T recommendation V.42 437 [4] Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". 438 available in ftp.uu.net:/pub/archiving/zip/doc/deflate-*.doc 440 [5] Gailly, J.-L., gzip documentation, available in 441 prep.ai.mit.edu:/pub/gnu/gzip-*.tar 443 [6] Sarwate, D.V., "Computation of Cyclic Redundancy Checks via Table 444 Look-Up", Communications of the ACM, 31(8), pp.1008-1013. 446 [7] Schwaderer, W.D., "CRC Calculation", April 85 PC Tech Journal, 447 pp.118-133. 449 [8] ftp.adelaide.edu.au:/pub/rocksoft/papers/crc_v3.txt, describing 450 the CRC concept. 452 Deutsch [Page 9] 453 4. Security considerations 455 Any data compression method involves the reduction of redundancy in 456 the data. Consequently, any corruption of the data is likely to have 457 severe effects and be difficult to correct. Uncompressed text, on 458 the other hand, will probably still be readable despite the presence 459 of some corrupted bytes. 461 It is recommended that systems using this data format provide some 462 means of validating the integrity of the compressed data, such as by 463 setting and checking the CRC-32 check value. 465 5. Acknowledgements 467 Trademarks cited in this document are the property of their 468 respective owners. 470 Jean-Loup Gailly designed the gzip format and wrote, with Mark Adler, 471 the related software described in this specification. Glenn 472 Randers-Pehrson converted this document to Internet Draft and HTML 473 format. 475 6. Author's address 477 L. Peter Deutsch 479 Aladdin Enterprises 480 203 Santa Margarita Ave. 481 Menlo Park, CA 94025 483 Phone: (415) 322-0103 (AM only) 484 FAX: (415) 322-1734 485 EMail: 487 Questions about the technical content of this specification can be 488 sent by email to 490 Jean-loup Gailly and 491 Mark Adler 493 Editorial comments on this specification can be sent by email to 495 L. Peter Deutsch and 496 Glenn Randers-Pehrson 498 Deutsch [Page 10] 499 7. Appendix: Jean-loup Gailly's gzip utility 501 The most widely used implementation of gzip compression, and the 502 original documentation on which this specification is based, were 503 created by Jean-loup Gailly . Since this 504 implementation is a de facto standard, we mention some more of its 505 features here. Again, the material in this section is not part of 506 the specification per se, and implementations need not follow it to 507 be compliant. 509 When compressing or decompressing a file, gzip preserves the 510 protection, ownership, and modification time attributes on the local 511 file system, since there is no provision for representing protection 512 attributes in the gzip file format itself. Since the file format 513 includes a modification time, the gzip decompressor provides a 514 command line switch that assigns the modification time from the file, 515 rather than the local modification time of the compressed input, to 516 the decompressed output. 518 8. Appendix: Sample CRC Code 520 The following sample code represents a practical implementation of 521 the CRC (Cyclic Redundancy Check). (See also ISO 3309 and ITU-T V.42 522 for a formal specification.) 524 The sample code is in the ANSI C programming language. Non C users 525 may find it easier to read with these hints: 527 & Bitwise AND operator. 528 ^ Bitwise exclusive-OR operator. 529 >> Bitwise right shift operator. When applied to an 530 unsigned quantity, as here, right shift inserts zero 531 bit(s) at the left. 532 ! Logical NOT operator. 533 ++ "n++" increments the variable n. 534 0xNNN 0x introduces a hexadecimal (base 16) constant. 535 Suffix L indicates a long value (at least 32 bits). 537 /* Table of CRCs of all 8-bit messages. */ 538 unsigned long crc_table[256]; 540 /* Flag: has the table been computed? Initially false. */ 541 int crc_table_computed = 0; 543 /* Make the table for a fast CRC. */ 544 void make_crc_table(void) 545 { 546 unsigned long c; 547 int n, k; 549 Deutsch [Page 11] 550 for (n = 0; n < 256; n++) { 551 c = (unsigned long) n; 552 for (k = 0; k < 8; k++) { 553 if (c & 1) { 554 c = 0xedb88320L ^ (c >> 1); 555 } else { 556 c = c >> 1; 557 } 558 } 559 crc_table[n] = c; 560 } 561 crc_table_computed = 1; 562 } 564 /* 565 Update a running crc with the bytes buf[0..len-1] and return 566 the updated crc. The crc should be initialized to zero. Pre- and 567 post-conditioning (one's complement) is performed within this 568 function so it shouldn't be done by the caller. Usage example: 570 unsigned long crc = 0L; 572 while (read_buffer(buffer, length) != EOF) { 573 crc = update_crc(crc, buffer, length); 574 } 575 if (crc != original_crc) error(); 576 */ 577 unsigned long update_crc(unsigned long crc, 578 unsigned char *buf, int len) 579 { 580 unsigned long c = crc ^ 0xffffffffL; 581 int n; 583 if (!crc_table_computed) 584 make_crc_table(); 585 for (n = 0; n < len; n++) { 586 c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8); 587 } 588 return c ^ 0xffffffffL; 589 } 591 /* Return the CRC of the bytes buf[0..len-1]. */ 592 unsigned long crc(unsigned char *buf, int len) 593 { 594 return update_crc(0L, buf, len); 595 } 597 Deutsch [Page 12]