ArticleslgStudy

computer science

XZ Utils

XZ Utils is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand XZ Utils rather than just read about it. In short: XZ Utils (previously LZMA Utils) is a set of free-software command-line lossless data compressors, including the programs lzma and xz, for Unix-like operating systems and, from version 5.0 onwards, Microsoft Windows. For compression/decompression the Lempel–Ziv–Markov chain algorithm (LZMA) is used.

Key takeaways

  • XZ Utils belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect XZ Utils to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of XZ Utils from memory before moving on to harder problems.

Reference excerpt

XZ Utils (previously LZMA Utils) is a set of free-software command-line lossless data compressors, including the programs lzma and xz, for Unix-like operating systems and, from version 5.0 onwards, Microsoft Windows. For compression/decompression the Lempel–Ziv–Markov chain algorithm (LZMA) is used. XZ Utils started as a Unix port of Igor Pavlov's LZMA-SDK that has been adapted to fit seamlessly into Unix environments and their usual structure and behavior.

Features XZ Utils can compress and decompress the xz and lzma file formats. Since the LZMA format has been considered legacy, XZ Utils by default compresses to xz. In addition, decompression of the .lz format used by lzip is supported since version 5.3.4. In most cases, xz achieves higher compression rates than alternatives like zip, gzip, and bzip2. Decompression speed is higher than bzip2, but lower than gzip. Compression can be much slower than gzip, and is slower than bzip2 for high levels of compression, and is most useful when a compressed file will be used many times. XZ Utils consists of two major components:

xz, the command-line compressor and decompressor (analogous to gzip) liblzma, a software library with an API similar to zlib Various command shortcuts exist, such as lzma (for xz --format=lzma), unxz (for xz --decompress; analogous to gunzip) and xzcat (for unxz --stdout; analogous to zcat).

Usage Both the behavior of the software and the properties of the file format have been designed to work similarly to those of the popular Unix compressing tools gzip and bzip2. Just like gzip and bzip, xz and lzma can only compress single files (or data streams) as input. They cannot bundle multiple files into a single archive – to do this an archiving program is used first, such as tar. Compressing an archive:

Decompressing the archive:

Version 1.22 or greater of the GNU implementation of tar has transparent support for tarballs compressed with lzma and xz, using the switches --xz or -J for xz compression, and --lzma for LZMA compression. Creating an archive and compressing it:

Decompressing the archive and extracting its contents:

Single-letter tar example for archive with compress and decompress with extract using short suffix:

xz has supported multi-threaded compression (with the -T flag) since 2014, version 5.2.0; since version 5.4.0, threaded decompression has been implemented. Threaded decompression requires multiple compressed blocks within a stream which are created by the threaded compression interface. The number of threads can be less than defined if the file is not big enough for threading with the given settings or if using more threads would exceed the memory-usage limit.

File format

An xz file is a sequence of one or more streams. There may be null bytes (padding) after each stream. The xz format improves on lzma by allowing for preprocessing filters (BCJ and delta). The exact filters used are similar to those used in 7z, as 7z's filters are available in the public domain via the LZMA SDK. xz's RISC-V BCJ filter is its own addition. Meta research from 2016 shows that xz has the highest compression ratio among lz4, zstd, and zlib, and the slowest compression/decompression. The author of lzip claims that the xz format is inadequate for general use due to its complexity and extensibility, saying that it puts xz-compressed data at an increased risk of undetected corruption. It is little-endian.

Stream structure

Block structure

Index structure

Variable-length integer Values from 0 to 127 are stored as-is, in one byte. Values greater than 127 (and up to 263) are stored in two or more bytes (up to 9). All bytes except the last one have the most significant bit set. The following Python code implements functions to encode and decode a variable-length integer.

Development and adoption Development of XZ Utils took place within the Tukaani Project, a small group of developers who once maintained a Linux distribution based on Slackware. The chosen name "XZ" is not an abbreviation but instead appears to be a random given name for the data compressors, as there is no mention anywhere in the official specification on the meaning of "XZ". The .xz file format specification version 1.0.0 was officially released in January 2009. All of the source code for xz and liblzma has been released into the public domain. The XZ Utils source distribution additionally includes some optional scripts and an example program that are subject to various versions of the GNU General Public License (GPL). The resulting software xz and liblzma binaries are public domain, unless the optional LGPL getopt implementation is incorporated. Binaries are available for FreeBSD, NetBSD, Linux systems, Microsoft Windows, and FreeDOS. A number of Linux distributions, including Fedora, Slackware, Ubuntu, and Debian use xz for compressing their software packages. Arch Linux previously used xz to compress packages, but as of 27 December 2019, packages are compressed with Zstandard compression. Fedora Linux also switched to compressing its RPM packages with Zstandard with Fedora Linux 31. The GNU FTP archive also uses xz.

Backdoor incident

On 29 March 2024, Andres Freund, a PostgreSQL developer working at Microsoft, announced that he had found a backdoor in XZ Utils, impacting versions 5.6.0 and 5.6.1. Malicious code for setting up the backdoor had been hidden in compressed test files, and the configure script in the tar files was modified to trigger the hidden code. Freund started his investigation "after observing a few odd symptoms around liblzma (part of the xz package)", specifically that ssh logins using sshd were "taking a lot of CPU" and producing valgrind errors. The vulnerability received a Common Vulnerability Scoring System (CVSS) score of 10 (the highest).

References

External links XZ Utils on SourceForge

Worked examples

Example 1 — a first encounter with XZ Utils

Start with the simplest possible case. Write down what XZ Utils claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to XZ Utils before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about XZ Utils ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of XZ Utils

In research
XZ Utils appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses XZ Utils in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
XZ Utils is common in secondary-school and first-year university syllabi. It links to neighbouring topics Free data compression software, Free software programmed in C, Public-domain software with source code, so understanding it makes those chapters shorter.
In everyday life
Look for XZ Utils outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “XZ Utils” →

How to study XZ Utils in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what XZ Utils means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain XZ Utils out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is XZ Utils in simple terms?

XZ Utils (previously LZMA Utils) is a set of free-software command-line lossless data compressors, including the programs lzma and xz, for Unix-like operating systems and, from version 5.0 onwards, Microsoft Windows. For compression/decompression the Lempel–Ziv–Markov chain algorithm (LZMA) is used.

Why does XZ Utils matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study XZ Utils?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on XZ Utils.

Tags

  • Free data compression software
  • Free software programmed in C
  • Public-domain software with source code
  • Software using the GNU General Public License
  • Unix archivers and compression-related utilities

Keep exploring