Difference between pages "Bzip2" and "Gzip"

From ForensicsWiki
(Difference between pages)
Jump to: navigation, search
 
(See Also)
 
Line 1: Line 1:
 
{{expand}}
 
{{expand}}
  
The bzip2 (.bz2) file consists of a single bzip2 stream. The bzip2 stream consists of:
+
== File format ==
* The stream header.
+
The gzip file (.gz) format consists of:
 +
* a file header
 +
* optional headers
 +
** extra fields
 +
** original file name
 +
** comment
 +
** header checksum
 +
* compressed data (commonly used compression method DEFLATE, without zlib header)
 +
* a file footer
  
The stream header is 4 bytes in size and contains:
+
{| class="wikitable"
 +
! align="left"| Characteristics
 +
! Description
 +
|-
 +
| Byte order
 +
| little-endian
 +
|-
 +
| Date and time values
 +
| Filetime in UTC
 +
|-
 +
| Character string
 +
| ISO 8859-1 (LATIN-1)
 +
|}
 +
 
 +
=== File header ===
 +
The file header is 10 bytes in size and contains:
 
{| class="wikitable"
 
{| class="wikitable"
 
! align="left"| Offset
 
! align="left"| Offset
Line 13: Line 36:
 
| 0
 
| 0
 
| 2
 
| 2
| "BZ"
+
| 0x1f 0x8b
| Signature (magic number)
+
| Signature (or identification byte 1 and 2)
 
|-
 
|-
 
| 2
 
| 2
 
| 1
 
| 1
 
|
 
|
| Version <br> 'h' for Bzip2 ('H'uffman coding), '0' for Bzip1 (deprecated)
+
| Compression Method
 
|-
 
|-
 
| 3
 
| 3
 
| 1
 
| 1
 
|
 
|
| Block size <br> Value is defined in increments of 100 kB <br> '1'..'9' block-size 100 kB-900 kB (uncompressed) <br> <b>Note: currently assumed that kB should be kiB</b>
+
| Flags
 +
|-
 +
| 4
 +
| 4
 +
|
 +
| Last modification time <br> Contains a POSIX timestamp.
 +
|-
 +
| 8
 +
| 1
 +
|
 +
| Compression flags (or extra flags)
 +
|-
 +
| 9
 +
| 1
 +
|
 +
| Operating system <br> Value that indicates on which operating system the gzip file was created.
 
|}
 
|}
  
* followed by zero or more compressed blocks
+
==== Compression method ====
<pre>
+
.compressed_magic:48            = 0x314159265359 (BCD (pi))
+
.crc:32                        = checksum for this block
+
.randomised:1                  = 0=>normal, 1=>randomised (deprecated)
+
.origPtr:24                    = starting pointer into BWT for after untransform
+
.huffman_used_map:16            = bitmap, of ranges of 16 bytes, present/not present
+
.huffman_used_bitmaps:0..256    = bitmap, of symbols used, present/not present (multiples of 16)
+
.huffman_groups:3              = 2..6 number of different Huffman tables in use
+
.selectors_used:15              = number of times that the Huffman tables are swapped (each 50 bytes)
+
*.selector_list:1..6            = zero-terminated bit runs (0..62) of MTF'ed Huffman table (*selectors_used)
+
.start_huffman_length:5        = 0..20 starting bit length for Huffman deltas
+
*.delta_bit_length:1..40        = 0=>next symbol; 1=>alter length
+
                                                { 1=>decrement length;  0=>increment length } (*(symbols+2)*groups)
+
.contents:2..∞                  = Huffman encoded data stream until end of block
+
</pre>
+
  
* immediately followed by an end-of-stream marker containing a 32-bit CRC for the uncompressed data.
+
{| class="wikitable"
<pre>
+
! align="left"| Value
.eos_magic:48                  = 0x177245385090 (BCD sqrt(pi))
+
! Identifier
.crc:32                        = checksum for whole stream
+
! Description
.padding:0..7                   = align to whole byte
+
|-
</pre>
+
| 0 - 7
 +
|
 +
| Reserved
 +
|-
 +
| 8
 +
| deflate
 +
| deflate compressed data
 +
|}
  
The compressed blocks are bit-aligned and no padding occurs.
+
==== Flags ====
 +
 
 +
{| class="wikitable"
 +
! align="left"| Value
 +
! Identifier
 +
! Description
 +
|-
 +
| 0x01
 +
| FTEXT
 +
| If set the uncompressed data needs to be treated as text instead of binary data. <br> This flag hints end-of-line conversion for cross-platform text files but does not enforce it.
 +
|-
 +
| 0x02
 +
| FHCRC
 +
| The file contains a header checksum (CRC-16)
 +
|-
 +
| 0x04
 +
| FEXTRA
 +
| The file contains extra fields
 +
|-
 +
| 0x08
 +
| FNAME
 +
| The file contains an original file name string
 +
|-
 +
| 0x10
 +
| FCOMMENT
 +
| The file contains comment
 +
|-
 +
| 0x20
 +
|
 +
| Reserved
 +
|-
 +
| 0x40
 +
|
 +
| Reserved
 +
|-
 +
| 0x80
 +
|
 +
| Reserved
 +
|}
 +
 
 +
<b>Notes:</b>
 +
* Reserved flags bits must be zero.
 +
* The FHCRC bit was never set by versions of gzip up to 1.2.4, even though it was documented with a different meaning in gzip 1.2.4.
 +
 
 +
==== Compression flags ====
 +
This value contains flags specific to the compression method.
 +
 
 +
===== Compression flags - deflate =====
 +
If compression method value is 8 (deflate) the following compression flags can be used:
 +
{| class="wikitable"
 +
! align="left"| Value
 +
! Identifier
 +
! Description
 +
|-
 +
| 0x02
 +
|
 +
| compressor used maximum compression, slowest algorithm
 +
|-
 +
| 0x04
 +
|
 +
| compressor used fastest algorithm
 +
|}
 +
 
 +
==== Operating System ====
 +
{| class="wikitable"
 +
! align="left"| Value
 +
! Identifier
 +
! Description
 +
|-
 +
| 0
 +
|
 +
| FAT filesystem (MS-DOS, OS/2, NT/Win32)
 +
|-
 +
| 1
 +
|
 +
| Amiga
 +
|-
 +
| 2
 +
|
 +
| VMS (or OpenVMS)
 +
|-
 +
| 3
 +
|
 +
| Unix
 +
|-
 +
| 4
 +
|
 +
| VM/CMS
 +
|-
 +
| 5
 +
|
 +
| Atari TOS
 +
|-
 +
| 6
 +
|
 +
| HPFS filesystem (OS/2, NT)
 +
|-
 +
| 7
 +
|
 +
| Macintosh
 +
|-
 +
| 8
 +
|
 +
| Z-System
 +
|-
 +
| 9
 +
|
 +
| CP/M
 +
|-
 +
| 10
 +
|
 +
| TOPS-20
 +
|-
 +
| 11
 +
|
 +
| NTFS filesystem (NT)
 +
|-
 +
| 12
 +
|
 +
| QDOS
 +
|-
 +
| 13
 +
|
 +
| Acorn RISCOS
 +
|-
 +
| 255
 +
|
 +
| unknown
 +
|}
 +
 
 +
=== Optional headers ===
 +
==== Extra fields ====
 +
This value is present in the file if the FEXTRA flag is set in the file header flags.
 +
 
 +
The extra field are variable of size and contains:
 +
{| class="wikitable"
 +
! align="left"| Offset
 +
! Size
 +
! Value
 +
! Description
 +
|-
 +
| 0
 +
| 2
 +
|
 +
| Extra field data size <br> Value in bytes.
 +
|-
 +
| 2
 +
| ...
 +
|
 +
| Extra field data
 +
|}
 +
 
 +
==== Original file name ====
 +
This value is present in the file if the FNAME flag is set in the file header flags.
 +
 
 +
This is the original name of the file being compressed, with any directory components removed, and, if the file being compressed is on a file system with case insensitive names, forced to lower case.
 +
 
 +
Contains an ISO 8859-1 (LATIN-1) string with end-of-string character.
 +
 
 +
==== Comment ====
 +
This value is present in the file if the FCOMMENT flag is set in the file header flags.
 +
 
 +
Contains an ISO 8859-1 (LATIN-1) string with end-of-string character. Line breaks should be denoted by a single line feed character.
 +
 
 +
==== Header checksum ====
 +
The header checksum contain a CRC-16 that consists of the two least significant bytes of the CRC-32 for all bytes of the gzip header up to and not including the CRC-16.
 +
 
 +
=== File footer ===
 +
The file footer is 8 bytes in size and contains:
 +
{| class="wikitable"
 +
! align="left"| Offset
 +
! Size
 +
! Value
 +
! Description
 +
|-
 +
| 0
 +
| 4
 +
|
 +
| Checksum (CRC-32)
 +
|-
 +
| 4
 +
| 4
 +
|
 +
| Uncompressed data size <br> Value in bytes.
 +
|}
  
== See also ==
+
== See Also ==
* [[gzip]]
+
* [[bzip2]]
 
* [[tar]]
 
* [[tar]]
  
 
== External Links ==
 
== External Links ==
  
* [http://en.wikipedia.org/wiki/Bzip2 Wikipedia: bzip2]
+
* [http://www.gzip.org/format.txt The gzip file format], by the [http://www.gzip.org/ gzip project]
 +
* [http://www.gzip.org/algorithm.txt The gzip compression algorithm], by the [http://www.gzip.org/ gzip project]
 +
* [http://tools.ietf.org/html/rfc1952 RFC1952: GZIP file format specification version 4.3], by [[IETF]]
 +
* [http://en.wikipedia.org/wiki/Gzip Wikipedia: gzip]
  
 
[[Category:File Formats]]
 
[[Category:File Formats]]

Revision as of 08:01, 30 November 2013

Information icon.png

Please help to improve this article by expanding it.
Further information might be found on the discussion page.

File format

The gzip file (.gz) format consists of:

  • a file header
  • optional headers
    • extra fields
    • original file name
    • comment
    • header checksum
  • compressed data (commonly used compression method DEFLATE, without zlib header)
  • a file footer
Characteristics Description
Byte order little-endian
Date and time values Filetime in UTC
Character string ISO 8859-1 (LATIN-1)

File header

The file header is 10 bytes in size and contains:

Offset Size Value Description
0 2 0x1f 0x8b Signature (or identification byte 1 and 2)
2 1 Compression Method
3 1 Flags
4 4 Last modification time
Contains a POSIX timestamp.
8 1 Compression flags (or extra flags)
9 1 Operating system
Value that indicates on which operating system the gzip file was created.

Compression method

Value Identifier Description
0 - 7 Reserved
8 deflate deflate compressed data

Flags

Value Identifier Description
0x01 FTEXT If set the uncompressed data needs to be treated as text instead of binary data.
This flag hints end-of-line conversion for cross-platform text files but does not enforce it.
0x02 FHCRC The file contains a header checksum (CRC-16)
0x04 FEXTRA The file contains extra fields
0x08 FNAME The file contains an original file name string
0x10 FCOMMENT The file contains comment
0x20 Reserved
0x40 Reserved
0x80 Reserved

Notes:

  • Reserved flags bits must be zero.
  • The FHCRC bit was never set by versions of gzip up to 1.2.4, even though it was documented with a different meaning in gzip 1.2.4.

Compression flags

This value contains flags specific to the compression method.

Compression flags - deflate

If compression method value is 8 (deflate) the following compression flags can be used:

Value Identifier Description
0x02 compressor used maximum compression, slowest algorithm
0x04 compressor used fastest algorithm

Operating System

Value Identifier Description
0 FAT filesystem (MS-DOS, OS/2, NT/Win32)
1 Amiga
2 VMS (or OpenVMS)
3 Unix
4 VM/CMS
5 Atari TOS
6 HPFS filesystem (OS/2, NT)
7 Macintosh
8 Z-System
9 CP/M
10 TOPS-20
11 NTFS filesystem (NT)
12 QDOS
13 Acorn RISCOS
255 unknown

Optional headers

Extra fields

This value is present in the file if the FEXTRA flag is set in the file header flags.

The extra field are variable of size and contains:

Offset Size Value Description
0 2 Extra field data size
Value in bytes.
2 ... Extra field data

Original file name

This value is present in the file if the FNAME flag is set in the file header flags.

This is the original name of the file being compressed, with any directory components removed, and, if the file being compressed is on a file system with case insensitive names, forced to lower case.

Contains an ISO 8859-1 (LATIN-1) string with end-of-string character.

Comment

This value is present in the file if the FCOMMENT flag is set in the file header flags.

Contains an ISO 8859-1 (LATIN-1) string with end-of-string character. Line breaks should be denoted by a single line feed character.

Header checksum

The header checksum contain a CRC-16 that consists of the two least significant bytes of the CRC-32 for all bytes of the gzip header up to and not including the CRC-16.

File footer

The file footer is 8 bytes in size and contains:

Offset Size Value Description
0 4 Checksum (CRC-32)
4 4 Uncompressed data size
Value in bytes.

See Also

External Links