xzlimit

package
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 6 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package xzlimit guards the xz decoder against streams that declare an oversized dictionary: the decoder allocates whatever the header asks for, up to 4 GiB, before reading any data. NewReader vets every block header against MaxDictSize first and decodes a single stream; CheckDictCap does the same for a stream already in memory.

Example
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"

	"github.com/ulikunitz/xz"

	"github.com/M0Rf30/pkgformat/xzlimit"
)

func main() {
	var packed bytes.Buffer

	w, _ := xz.NewWriter(&packed)
	_, _ = w.Write([]byte("Packages index"))
	_ = w.Close()

	r, err := xzlimit.NewReader(bufio.NewReader(&packed))
	if err != nil {
		fmt.Println(err)

		return
	}

	out, _ := io.ReadAll(r)
	fmt.Println(string(out))

}
Output:
Packages index

Index

Examples

Constants

View Source
const MaxDictSize = 64 << 20

MaxDictSize bounds the LZ window (xz dictionary / zstd window) an untrusted stream may declare. The decoders allocate it up front, so a tiny crafted stream could otherwise demand gigabytes; 64 MiB covers `xz -9`.

Variables

View Source
var ErrDictTooLarge = errors.New("xz dictionary size exceeds limit")

ErrDictTooLarge is returned for an xz stream declaring an oversized dictionary.

Functions

func CheckDictCap

func CheckDictCap(raw []byte) error

CheckDictCap walks the blocks of the (first) xz stream in raw and rejects it when any block's LZMA2 filter declares a dictionary larger than MaxDictSize. Anything it cannot parse is left to the decoder to reject. It does not inspect further streams; use NewReader for untrusted streaming input.

func NewReader

func NewReader(br *bufio.Reader) (io.Reader, error)

NewReader returns an xz decoder over br. Every block header of the stream is inspected before the decoder sees it, and a block declaring a dictionary above MaxDictSize is rejected with ErrDictTooLarge. The decoder is limited to a single stream (trailing data or a second stream is an error), because the decoder raises its dictionary to whatever each later stream or block declares.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL