mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-09-11 05:43:16 -04:00
process_comp_header() is called from zstd_compress_stream_to_records() twice per record: once with data_size == 0 to write the record header, and once with the payload size to finalize it. It returns the increment it was passed, and the loop separately decides whether a record still fits by comparing the remaining 'dst_size' against the header size. With the fit check split from the code that writes the record, process_comp_header() cannot reject a record on its own, so any bytes it writes into 'dst' have to be bounds-checked by the caller instead of where they are produced. Pass the space left in 'dst' to process_comp_header(), let it return the number of bytes written or -1 when the header does not fit, and account the compressed payload in the loop. No functional change intended. Signed-off-by: Dmitry Ilvokhin <d@ilvokhin.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
94 lines
2.4 KiB
C
94 lines
2.4 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef PERF_COMPRESS_H
|
|
#define PERF_COMPRESS_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <sys/types.h>
|
|
#include <linux/compiler.h>
|
|
#ifdef HAVE_ZSTD_SUPPORT
|
|
#include <zstd.h>
|
|
#endif
|
|
|
|
#ifdef HAVE_ZLIB_SUPPORT
|
|
int gzip_decompress_to_file(const char *input, int output_fd);
|
|
bool gzip_is_compressed(const char *input);
|
|
#endif
|
|
|
|
#ifdef HAVE_LZMA_SUPPORT
|
|
int lzma_decompress_stream_to_file(FILE *input, int output_fd);
|
|
int lzma_decompress_to_file(const char *input, int output_fd);
|
|
bool lzma_is_compressed(const char *input);
|
|
#else
|
|
static inline
|
|
int lzma_decompress_stream_to_file(FILE *input __maybe_unused,
|
|
int output_fd __maybe_unused)
|
|
{
|
|
return -1;
|
|
}
|
|
static inline
|
|
int lzma_decompress_to_file(const char *input __maybe_unused,
|
|
int output_fd __maybe_unused)
|
|
{
|
|
return -1;
|
|
}
|
|
static inline int lzma_is_compressed(const char *input __maybe_unused)
|
|
{
|
|
return false;
|
|
}
|
|
#endif
|
|
|
|
struct zstd_data {
|
|
#ifdef HAVE_ZSTD_SUPPORT
|
|
ZSTD_CStream *cstream;
|
|
ZSTD_DStream *dstream;
|
|
int comp_level;
|
|
#endif
|
|
};
|
|
|
|
#ifdef HAVE_ZSTD_SUPPORT
|
|
|
|
int zstd_init(struct zstd_data *data, int level);
|
|
int zstd_fini(struct zstd_data *data);
|
|
|
|
ssize_t zstd_compress_stream_to_records(struct zstd_data *data, void *dst, size_t dst_size,
|
|
void *src, size_t src_size, size_t max_record_size,
|
|
ssize_t process_header(void *record, size_t dst_size,
|
|
size_t data_size));
|
|
|
|
size_t zstd_decompress_stream(struct zstd_data *data, void *src, size_t src_size,
|
|
void *dst, size_t dst_size);
|
|
#else /* !HAVE_ZSTD_SUPPORT */
|
|
|
|
static inline int zstd_init(struct zstd_data *data __maybe_unused, int level __maybe_unused)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline int zstd_fini(struct zstd_data *data __maybe_unused)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline
|
|
ssize_t zstd_compress_stream_to_records(struct zstd_data *data __maybe_unused,
|
|
void *dst __maybe_unused, size_t dst_size __maybe_unused,
|
|
void *src __maybe_unused, size_t src_size __maybe_unused,
|
|
size_t max_record_size __maybe_unused,
|
|
ssize_t process_header(void *record, size_t dst_size,
|
|
size_t data_size) __maybe_unused)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline size_t zstd_decompress_stream(struct zstd_data *data __maybe_unused, void *src __maybe_unused,
|
|
size_t src_size __maybe_unused, void *dst __maybe_unused,
|
|
size_t dst_size __maybe_unused)
|
|
{
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
#endif /* PERF_COMPRESS_H */
|