From aa7124d3b889a1d8a9a589331a3c9580db29d716 Mon Sep 17 00:00:00 2001
From: Dominik Loidolt <dominik.loidolt@univie.ac.at>
Date: Wed, 14 Feb 2024 10:58:45 +0100
Subject: [PATCH] Remove error debug_print() in put_n_bits32 in case of a small
 buffer error

In chunk compression, intentionally limit the buffer to detect cases
where uncompressed data are shorter than compressed data. The debug print
was printing errors even when this behaviour was intended.
---
 lib/icu_compress/cmp_icu.c | 4 +---
 programs/cmp_tool.c        | 5 ++++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/icu_compress/cmp_icu.c b/lib/icu_compress/cmp_icu.c
index 5e6f13f..1f217a0 100644
--- a/lib/icu_compress/cmp_icu.c
+++ b/lib/icu_compress/cmp_icu.c
@@ -466,10 +466,8 @@ static int put_n_bits32(uint32_t value, unsigned int n_bits, int bit_offset,
 		return stream_len;
 
 	/* Check if bitstream buffer is large enough */
-	if ((unsigned int)stream_len > max_stream_len) {
-		debug_print("Error: The buffer for the compressed data is too small to hold the compressed data. Try a larger buffer_length parameter.\n");
+	if ((unsigned int)stream_len > max_stream_len)
 		return CMP_ERROR_SMALL_BUF;
-	}
 
 	local_adr = bitstream_adr + (bit_offset >> 5);
 
diff --git a/programs/cmp_tool.c b/programs/cmp_tool.c
index c70c7bf..9560c9d 100644
--- a/programs/cmp_tool.c
+++ b/programs/cmp_tool.c
@@ -773,8 +773,11 @@ static int compression(struct cmp_cfg *cfg, struct cmp_info *info)
 	cfg->icu_output_buf = cmp_ent_get_data_buf(cmp_entity);
 
 	cmp_size = icu_compress_data(cfg);
-	if (cmp_size < 0)
+	if (cmp_size < 0) {
+		if (cmp_size == CMP_ERROR_SMALL_BUF)
+			fprintf(stderr, "Error: The buffer for the compressed data is too small to hold the compressed data. Try a larger buffer_length parameter.\n");
 		goto error_cleanup;
+	}
 
 	if (model_id_str) {
 		uint32_t red_val;
-- 
GitLab