blob: 655adbfcd184e374298c8a07fcec74e034f3277d [file] [log] [blame]
Simon Glasse1aba1e2019-11-14 12:57:25 -07001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright 2019 Google LLC
4 */
5
6#ifndef __LZ4_H
7#define __LZ4_H
8
9/**
10 * ulz4fn() - Decompress LZ4 data
11 *
12 * @src: Source data to decompress
13 * @srcn: Length of source data
14 * @dst: Destination for uncompressed data
15 * @dstn: Returns length of uncompressed data
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010016 * Return: 0 if OK, -EPROTONOSUPPORT if the magic number or version number are
Simon Glasse1aba1e2019-11-14 12:57:25 -070017 * not recognised or independent blocks are used, -EINVAL if the reserved
18 * fields are non-zero, or input is overrun, -EENOBUFS if the destination
19 * buffer is overrun, -EEPROTO if the compressed data causes an error in
20 * the decompression algorithm
21 */
22int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn);
23
Huang Jianan24a0c502022-02-26 15:05:48 +080024/**
25 * LZ4_decompress_safe() - Decompression protected against buffer overflow
26 * @source: source address of the compressed data
27 * @dest: output buffer address of the uncompressed data
28 * which must be already allocated
29 * @compressedSize: is the precise full size of the compressed block
30 * @maxDecompressedSize: is the size of 'dest' buffer
31 *
32 * Decompresses data from 'source' into 'dest'.
33 * If the source stream is detected malformed, the function will
34 * stop decoding and return a negative result.
35 * This function is protected against buffer overflow exploits,
36 * including malicious data packets. It never writes outside output buffer,
37 * nor reads outside input buffer.
38 *
39 * Return: number of bytes decompressed into destination buffer
40 * (necessarily <= maxDecompressedSize)
41 * or a negative result in case of error
42 */
43int LZ4_decompress_safe(const char *source, char *dest,
44 int compressedSize, int maxDecompressedSize);
45
46/**
47 * LZ4_decompress_safe_partial() - Decompress a block of size 'compressedSize'
48 * at position 'source' into buffer 'dest'
49 * @source: source address of the compressed data
50 * @dest: output buffer address of the decompressed data which must be
51 * already allocated
52 * @compressedSize: is the precise full size of the compressed block.
53 * @targetOutputSize: the decompression operation will try
54 * to stop as soon as 'targetOutputSize' has been reached
55 * @maxDecompressedSize: is the size of destination buffer
56 *
57 * This function decompresses a compressed block of size 'compressedSize'
58 * at position 'source' into destination buffer 'dest'
59 * of size 'maxDecompressedSize'.
60 * The function tries to stop decompressing operation as soon as
61 * 'targetOutputSize' has been reached, reducing decompression time.
62 * This function never writes outside of output buffer,
63 * and never reads outside of input buffer.
64 * It is therefore protected against malicious data packets.
65 *
66 * Return: the number of bytes decoded in the destination buffer
67 * (necessarily <= maxDecompressedSize)
68 * or a negative result in case of error
69 *
70 */
71int LZ4_decompress_safe_partial(const char *src, char *dst,
72 int compressedSize, int targetOutputSize, int dstCapacity);
Simon Glasse1aba1e2019-11-14 12:57:25 -070073#endif