idnits 2.17.00 (12 Aug 2021) /tmp/idnits59520/draft-deutsch-gzip-spec-01.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 (12 Feb 1996) is 9594 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 551, but not defined == Unused Reference: '1' is defined on line 449, but no explicit reference was found in the text == Unused Reference: '2' is defined on line 453, but no explicit reference was found in the text == Unused Reference: '3' is defined on line 456, but no explicit reference was found in the text == Unused Reference: '4' is defined on line 459, but no explicit reference was found in the text == Unused Reference: '5' is defined on line 462, 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' Summary: 8 errors (**), 0 flaws (~~), 9 warnings (==), 8 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 1 INTERNET-DRAFT L. Peter Deutsch 2 GZIP 4.3 Aladdin Enterprises 3 Expires: 17 Aug 1996 12 Feb 1996 5 GZIP file format specification version 4.3 7 File draft-deutsch-gzip-spec-01.txt 9 Status of this Memo 11 This document is an Internet-Draft. Internet-Drafts are working 12 documents of the Internet Engineering Task Force (IETF), its areas, 13 and its working groups. Note that other groups may also distribute 14 working documents as Internet-Drafts. 16 Internet-Drafts are draft documents valid for a maximum of six months 17 and may be updated, replaced, or obsoleted by other documents at any 18 time. It is inappropriate to use Internet- Drafts as reference 19 material or to cite them other than as ``work in progress.'' 21 To learn the current status of any Internet-Draft, please check the 22 ``1id-abstracts.txt'' listing contained in the Internet- Drafts 23 Shadow Directories on ftp.is.co.za (Africa), nic.nordu.net (Europe), 24 munnari.oz.au (Pacific Rim), ds.internic.net (US East Coast), or 25 ftp.isi.edu (US West Coast). 27 Distribution of this memo is unlimited. 29 Notices 31 Copyright (C) 1996 L. Peter Deutsch 33 Permission is granted to copy and distribute this document for any 34 purpose and without charge, including translations into other 35 languages and incorporation into compilations, provided that it is 36 copied as a whole (including the copyright notice and this notice) 37 and with no changes. 39 Abstract 41 This specification defines a lossless compressed data format that is 42 compatible with the widely used GZIP utility. The format includes a 43 cyclic redundancy check value for detecting data corruption. The 44 format presently uses the DEFLATE method of compression but can be 45 easily extended to use other compression methods. The format can be 46 implemented readily in a manner not covered by patents. 48 Table of contents 50 Deutsch [Page 1] 51 1. Introduction ................................................... 2 52 1.1 Purpose .................................................... 2 53 1.2 Intended audience .......................................... 2 54 1.3 Scope ...................................................... 3 55 1.4 Compliance ................................................. 3 56 1.5 Definitions of terms and conventions used .................. 3 57 1.6 Changes from previous versions ............................. 3 58 2. Detailed specification ......................................... 3 59 2.1 Overall conventions ........................................ 3 60 2.2 File format ................................................ 4 61 2.3 Member format .............................................. 4 62 2.3.1. Member header and trailer ........................... 5 63 2.3.1.1. Extra field ....................................... 8 64 2.3.1.2. Compliance ........................................ 8 65 3. References ..................................................... 9 66 3.1 Related standards .......................................... 9 67 3.2 Other related publications ................................. 9 68 4. Security considerations ........................................ 9 69 5. Acknowledgements .............................................. 10 70 6. Author's address .............................................. 10 71 7. Appendix: Jean-loup Gailly's gzip utility ..................... 10 72 8. Appendix: Sample CRC Code ..................................... 11 74 1. Introduction 76 1.1. Purpose 78 The purpose of this specification is to define a lossless 79 compressed data format that: 80 o Is independent of CPU type, operating system, file system, 81 and character set, and hence can be used for interchange; 82 o 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 o 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 o Can be implemented readily in a manner not covered by 92 patents, and hence can be practiced freely; 93 o Is compatible with the file format produced by the current 94 widely used gzip utility, in that conforming decompressors 95 will be able to read data produced by the existing gzip 96 compressor. 98 The data format defined by this specification does not attempt to: 99 o Provide random access to compressed data; 100 o Compress specialized data (e.g., raster graphics) as well as 101 the best currently available specialized algorithms. 102 1.2. Intended audience 104 Deutsch [Page 2] 105 This specification is intended for use by implementors of software 106 to compress data into gzip format and/or decompress data from gzip 107 format. 109 The text of the specification assumes a basic background in 110 programming at the level of bits and other primitive data 111 representations. 113 1.3. Scope 115 The specification specifies a compression method and a file format 116 (the latter assuming only that a file can store a sequence of 117 arbitrary bytes). It does not specify any particular interface to 118 a file system or anything about character sets or encodings 119 (except for file names and comments, which are optional). 121 1.4. Compliance 123 Unless otherwise indicated below, a compliant decompressor must be 124 able to accept and decompress any file that conforms to all the 125 specifications presented here; a compliant compressor must produce 126 files that conform to all the specifications presented here. The 127 material in the appendices is not part of the specification per se 128 and is not relevant to compliance. 130 1.5. Definitions of terms and conventions used 132 byte: 8 bits stored or transmitted as a unit (same as an octet). 133 (For this specification, a byte is exactly 8 bits, even on 134 machines which store a character on a number of bits different 135 from 8.) See Section 2.1, below for the numbering of bits within 136 a byte. 138 1.6. Changes from previous versions 140 There have been no technical changes to the gzip format since 141 version 4.1 of this specification. In version 4.2, some 142 terminology was changed, and the sample CRC code was rewritten for 143 clarity and to eliminate the requirement for the caller to do pre- 144 and post-conditioning. Version 4.3 is a conversion of the 145 specification to Internet Draft style. 147 2. Detailed specification 149 2.1. Overall conventions 151 In the diagrams below, a box like this: 153 +---+ 154 | | <-- the vertical bars might be missing 155 +---+ 157 Deutsch [Page 3] 158 represents one byte; a box like this: 160 +==============+ 161 | | 162 +==============+ 164 represents a variable number of bytes. 166 Bytes stored within a computer do not have a 'bit order', since 167 they are always treated as a unit. However, a byte considered as 168 an integer between 0 and 255 does have a most- and least- 169 significant bit, and since we write numbers with the most- 170 significant digit on the left, we also write bytes with the most- 171 significant bit on the left. In the diagrams below, we number the 172 bits of a byte so that bit 0 is the least-significant bit, i.e., 173 the bits are numbered: 175 +--------+ 176 |76543210| 177 +--------+ 179 This document does not address the issue of the order in which 180 bits of a byte are transmitted on a bit-sequential medium, since 181 the data format described here is byte- rather than bit-oriented. 183 Within a computer, a number may occupy multiple bytes. All 184 multi-byte numbers in the format described here are stored with 185 the least-significant byte first (at the lower memory address). 186 For example, the decimal number 520 is stored as: 188 0 1 189 +--------+--------+ 190 |00001000|00000010| 191 +--------+--------+ 192 ^ ^ 193 | | 194 | + more significant byte = 2 x 256 195 + less significant byte = 8 197 2.2. File format 199 A gzip file consists of a series of "members" (compressed data 200 sets). The format of each member is specified in the following 201 section. The members simply appear one after another in the file, 202 with no additional information before, between, or after them. 204 2.3. Member format 206 Each member has the following structure: 208 Deutsch [Page 4] 209 +---+---+---+---+---+---+---+---+---+---+ 210 |ID1|ID2|CM |FLG| MTIME |XFL|OS | (more-->) 211 +---+---+---+---+---+---+---+---+---+---+ 213 (if FLG.FEXTRA set) 215 +---+---+=================================+ 216 | XLEN |...XLEN bytes of 'extra field'...| (more-->) 217 +---+---+=================================+ 219 (if FLG.FNAME set) 221 +=========================================+ 222 |...original file name, zero-terminated...| (more-->) 223 +=========================================+ 225 (if FLG.FCOMMENT set) 227 +===================================+ 228 |...file comment, zero-terminated...| (more-->) 229 +===================================+ 231 (if FLG.FHCRC set) 233 +---+---+ 234 | CRC16 | 235 +---+---+ 237 +=======================+ 238 |...compressed blocks...| (more-->) 239 +=======================+ 241 0 1 2 3 4 5 6 7 242 +---+---+---+---+---+---+---+---+ 243 | CRC32 | ISIZE | 244 +---+---+---+---+---+---+---+---+ 246 2.3.1. Member header and trailer 248 ID1 (IDentification 1) 250 ID2 (IDentification 2) 252 These have the fixed values ID1 = 31 (0x1f, \037), ID2 = 139 253 (0x8b, \213), to identify the file as being in gzip format. 255 CM (Compression Method) 257 This identifies the compression method used in the file. CM 258 = 0-7 are reserved. CM = 8 denotes the 'deflate' 259 compression method, which is the one customarily used by 260 gzip and which is documented elsewhere. 262 Deutsch [Page 5] 263 FLG (FLaGs) 265 This flag byte is divided into individual bits as follows: 267 bit 0 FTEXT 268 bit 1 FHCRC 269 bit 2 FEXTRA 270 bit 3 FNAME 271 bit 4 FCOMMENT 272 bit 5 reserved 273 bit 6 reserved 274 bit 7 reserved 276 If FTEXT is set, the file is probably ASCII text. This is 277 an optional indication, which the compressor may set by 278 checking a small amount of the input data to see whether any 279 non-ASCII characters are present. In case of doubt, FTEXT 280 is cleared, indicating binary data. For systems which have 281 different file formats for ascii text and binary data, the 282 decompressor can use FTEXT to choose the appropriate format. 283 We deliberately do not specify the algorithm used to set 284 this bit, since a compressor always has the option of 285 leaving it cleared and a decompressor always has the option 286 of ignoring it and letting some other program handle issues 287 of data conversion. 289 If FHCRC is set, a CRC16 for the gzip header is present, 290 immediately before the compressed data. The CRC16 consists 291 of the two least significant bytes of the CRC32 for all 292 bytes of the gzip header up to and not including the CRC16. 293 [The FHCRC bit was never set by versions of gzip up to 294 1.2.4, even though it was documented with a different 295 meaning in gzip 1.2.4.] 297 If FEXTRA is set, optional extra fields are present, as 298 described in a following section. 300 If FNAME is set, an original file name is present, 301 terminated by a zero byte. The name must consist of ISO 302 8859-1 (LATIN-1) characters; on operating systems using 303 EBCDIC or any other character set for file names, the name 304 must be translated to the ISO LATIN-1 character set. This 305 is the original name of the file being compressed, with any 306 directory components removed, and, if the file being 307 compressed is on a file system with case insensitive names, 308 forced to lower case. There is no original file name if the 309 data was compressed from a source other than a named file; 310 for example, if the source was stdin on a Unix system, there 311 is no file name. 313 If FCOMMENT is set, a zero-terminated file comment is 314 present. This comment is not interpreted; it is only 316 Deutsch [Page 6] 317 intended for human consumption. The comment must consist of 318 ISO 8859-1 (LATIN-1) characters. Line breaks should be 319 denoted by a single line feed character (10 decimal). 321 Reserved FLG bits must be zero. 323 MTIME (Modification TIME) 325 This gives the most recent modification time of the original 326 file being compressed. The time is in Unix format, i.e., 327 seconds since 00:00:00 GMT, Jan. 1, 1970. (Note that this 328 may cause problems for MS-DOS and other systems that use 329 local rather than Universal time.) If the compressed data 330 did not come from a file, MTIME is set to the time at which 331 compression started. MTIME = 0 means no time stamp is 332 available. 334 XFL (eXtra FLags) 336 These flags are available for use by specific compression 337 methods. The 'deflate' method (CM = 8) sets these flags as 338 follows: 340 XFL = 2 - compressor used maximum compression, 341 slowest algorithm 342 XFL = 4 - compressor used fastest algorithm 344 OS (Operating System) 346 This identifies the type of file system on which compression 347 took place. This may be useful in determining end-of-line 348 convention for text files. The currently defined values are 349 as follows: 351 0 - FAT filesystem (MS-DOS, OS/2, NT/Win32) 352 1 - Amiga 353 2 - VMS (or OpenVMS) 354 3 - Unix 355 4 - VM/CMS 356 5 - Atari TOS 357 6 - HPFS filesystem (OS/2, NT) 358 7 - Macintosh 359 8 - Z-System 360 9 - CP/M 361 10 - TOPS-20 362 11 - NTFS filesystem (NT) 363 12 - QDOS 364 13 - Acorn RISCOS 365 255 - unknown 367 XLEN (eXtra LENgth) 369 Deutsch [Page 7] 370 If FLG.FEXTRA is set, this gives the length of the optional 371 extra field. See below for details. 373 CRC32 (CRC-32) 375 This contains a Cyclic Redundancy Check value of the 376 uncompressed data computed according to CRC-32 algorithm 377 used in the ISO 3309 standard and in section 8.1.1.6.2 of 378 ITU-T recommendation V.42. (See http://www.iso.ch for 379 ordering ISO documents. See gopher://info.itu.ch for an 380 online version of ITU-T V.42.) 382 ISIZE (Input SIZE) 384 This contains the size of the original (uncompressed) input 385 data modulo 2^32. 387 2.3.1.1. Extra field 389 If the FLG.FEXTRA bit is set, an "extra field" is present in 390 the header, with total length XLEN bytes. It consists of a 391 series of subfields, each of the form: 393 +---+---+---+---+==================================+ 394 |SI1|SI2| LEN |... LEN bytes of subfield data ...| 395 +---+---+---+---+==================================+ 397 SI1 and SI2 provide a subfield ID, typically two ASCII letters 398 with some mnemonic value. Jean-loup Gailly 399 is maintaining a registry of subfield 400 IDs; please send him any subfield ID you wish to use. Subfield 401 IDs with SI2 = 0 are reserved for future use. The following 402 IDs are currently defined: 404 SI1 SI2 Data 405 ---------- ---------- ---- 406 0x41 ('A') 0x70 ('P') Apollo file type information 408 LEN gives the length of the subfield data, excluding the 4 409 initial bytes. 411 2.3.1.2. Compliance 413 A compliant compressor must produce files with correct ID1, 414 ID2, CM, CRC32, and ISIZE, but may set all the other fields in 415 the fixed-length part of the header to default values (255 for 416 OS, 0 for all others). The compressor must set all reserved 417 bits to zero. 419 A compliant decompressor must check ID1, ID2, and CM, and 420 provide an error indication if any of these have incorrect 421 values. It must examine FEXTRA/XLEN, FNAME, FCOMMENT and FHCRC 423 Deutsch [Page 8] 424 at least so it can skip over the optional fields if they are 425 present. It need not examine any other part of the header or 426 trailer; in particular, a decompressor may ignore FTEXT and OS 427 and always produce binary output, and still be compliant. A 428 compliant decompressor must give an error indication if any 429 reserved bit is non-zero, since such a bit could indicate the 430 presence of a new field that would cause subsequent data to be 431 interpreted incorrectly. 433 3. References 435 3.1. Related standards 437 "Information Processing - 8-bit single-byte coded graphic 438 character sets - Part 1: Latin alphabet No.1" (ISO 8859-1:1987). 439 The ISO 8859-1 (Latin-1) character set is a superset of 7-bit 440 ASCII. Files defining this character set may be obtained from 441 ftp.uu.net:/graphics/png/documents/iso_8859-1.* 443 ISO 3309 445 ITU-T recommendation V.42 447 3.2. Other related publications 449 [1] Deutsch, L.P.,"'Deflate' Compressed Data Format 450 Specification". available in 451 ftp.uu.net:/pub/archiving/zip/doc/deflate-*.doc 453 [2] Gailly, J.-L., gzip documentation, available in 454 prep.ai.mit.edu:/pub/gnu/gzip-*.tar 456 [3] Sarwate, D.V., "Computation of Cyclic Redundancy Checks via 457 Table Look-Up", Communications of the ACM, 31(8), pp.1008-1013. 459 [4] Schwaderer, W.D., "CRC Calculation", April 85 PC Tech Journal, 460 pp.118-133. 462 [5] ftp.adelaide.edu.au:/pub/rocksoft/papers/crc_v3.txt, 463 describing the CRC concept. 465 4. Security considerations 467 Any data compression method involves the reduction of redundancy in 468 the data. Consequently, any corruption of the data is likely to have 469 severe effects and be difficult to correct. Uncompressed text, on 470 the other hand, will probably still be readable despite the presence 471 of some corrupted bytes. 473 It is recommended that systems using this data format provide some 474 means of validating the integrity of the compressed data, such as by 475 setting and checking the CRC-32 check value. 477 Deutsch [Page 9] 478 5. Acknowledgements 480 Trademarks cited in this document are the property of their 481 respective owners. 483 Jean-Loup Gailly designed the gzip format and wrote, with Mark Adler, 484 the related software described in this specification. Glenn 485 Randers-Pehrson converted this document to Internet Draft and HTML 486 format. 488 6. Author's address 490 L. Peter Deutsch 492 Aladdin Enterprises 493 203 Santa Margarita Ave. 494 Menlo Park, CA 94025 496 Phone: (415) 322-0103 (AM only) 497 FAX: (415) 322-1734 498 EMail: 500 Questions about the technical content of this specification can be 501 sent by email to 503 Jean-loup Gailly and 504 Mark Adler 506 Editorial comments on this specification can be sent by email to 508 L. Peter Deutsch and 509 Glenn Randers-Pehrson 511 7. Appendix: Jean-loup Gailly's gzip utility 513 The most widely used implementation of gzip compression, and the 514 original documentation on which this specification is based, were 515 created by Jean-loup Gailly . Since this 516 implementation is a de facto standard, we mention some more of its 517 features here. Again, the material in this section is not part of 518 the specification per se, and implementations need not follow it to 519 be compliant. 521 When compressing or decompressing a file, gzip preserves the 522 protection, ownership, and modification time attributes on the local 523 file system, since there is no provision for representing protection 524 attributes in the gzip file format itself. Since the file format 525 includes a modification time, the gzip decompressor provides a 526 command line switch that assigns the modification time from the file, 527 rather than the local modification time of the compressed input, to 528 the decompressed output. 530 Deutsch [Page 10] 531 8. Appendix: Sample CRC Code 533 The following sample code represents a practical implementation of 534 the CRC (Cyclic Redundancy Check). (See also ISO 3309 and ITU-T V.42 535 for a formal specification.) 537 The sample code is in the ANSI C programming language. Non C users 538 may find it easier to read with these hints: 540 & Bitwise AND operator. 541 ^ Bitwise exclusive-OR operator. 542 >> Bitwise right shift operator. When applied to an 543 unsigned quantity, as here, right shift inserts zero 544 bit(s) at the left. 545 ! Logical NOT operator. 546 ++ "n++" increments the variable n. 547 0xNNN 0x introduces a hexadecimal (base 16) constant. 548 Suffix L indicates a long value (at least 32 bits). 550 /* Table of CRCs of all 8-bit messages. */ 551 unsigned long crc_table[256]; 553 /* Flag: has the table been computed? Initially false. */ 554 int crc_table_computed = 0; 556 /* Make the table for a fast CRC. */ 557 void make_crc_table(void) 558 { 559 unsigned long c; 560 int n, k; 562 for (n = 0; n < 256; n++) { 563 c = (unsigned long) n; 564 for (k = 0; k < 8; k++) { 565 if (c & 1) { 566 c = 0xedb88320L ^ (c >> 1); 567 } else { 568 c = c >> 1; 569 } 570 } 571 crc_table[n] = c; 572 } 573 crc_table_computed = 1; 574 } 576 Deutsch [Page 11] 577 /* 578 Update a running crc with the bytes buf[0..len-1] and return 579 the updated crc. The crc should be initialized to zero. Pre- and 580 post-conditioning (one's complement) is performed within this 581 function so it shouldn't be done by the caller. Usage example: 583 unsigned long crc = 0L; 585 while (read_buffer(buffer, length) != EOF) { 586 crc = update_crc(crc, buffer, length); 587 } 588 if (crc != original_crc) error(); 589 */ 590 unsigned long update_crc(unsigned long crc, 591 unsigned char *buf, int len) 592 { 593 unsigned long c = crc ^ 0xffffffffL; 594 int n; 596 if (!crc_table_computed) 597 make_crc_table(); 598 for (n = 0; n < len; n++) { 599 c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8); 600 } 601 return c ^ 0xffffffffL; 602 } 604 /* Return the CRC of the bytes buf[0..len-1]. */ 605 unsigned long crc(unsigned char *buf, int len) 606 { 607 return update_crc(0L, buf, len); 608 } 610 Deutsch [Page 12]