@@ -119,11 +119,56 @@ static void test_compress_decompress_large_data() {
119119 flb_free (decompressed_data );
120120}
121121
122+ /*
123+ * zstd can contain a payload with an unknown registered size, as an example we have this payload
124+ * that can be generated from the command line:
125+ *
126+ * $ echo -n '{"hello":"world"}' | zstd > data.json.stream.zstd
127+ *
128+ * $zstd -l data.json.stream.zstd
129+ *
130+ * Frames Skips Compressed Uncompressed Ratio Check Filename
131+ * 1 0 31 B XXH64 data.json.streamed.zstd
132+ *
133+ * note: to regenerate the payload in the compressed_data buffer, you can use the following command:
134+ *
135+ * $ xxd -i data.json.stream.zstd
136+ */
137+ static void test_decompress_unknown_size ()
138+ {
139+ int ret ;
140+ int input_len = 0 ;
141+ int compressed_len ;
142+ char * input = "{\"hello\":\"world\"}" ;
143+ void * decompressed_data ;
144+ size_t decompressed_len ;
145+
146+ /* this is data.json.stream.zstd in a buffer representation (hexdump data.json.streamed.zstd )*/
147+ unsigned char compressed_data [30 ] = {
148+ 0x28 , 0xb5 , 0x2f , 0xfd , 0x04 , 0x58 , 0x89 , 0x00 , 0x00 , 0x7b , 0x22 , 0x68 ,
149+ 0x65 , 0x6c , 0x6c , 0x6f , 0x22 , 0x3a , 0x22 , 0x77 , 0x6f , 0x72 , 0x6c , 0x64 ,
150+ 0x22 , 0x7d , 0x8e , 0x23 , 0xa6 , 0x52
151+ };
152+
153+ compressed_len = sizeof (compressed_data );
154+ input_len = strlen (input );
155+
156+ /* decompress */
157+ ret = flb_zstd_uncompress (compressed_data , compressed_len , & decompressed_data , & decompressed_len );
158+ TEST_CHECK (ret == 0 );
159+ TEST_CHECK (decompressed_data != NULL );
160+ TEST_CHECK (decompressed_len == input_len );
161+ TEST_CHECK (memcmp (decompressed_data , input , input_len ) == 0 );
162+
163+ flb_free (decompressed_data );
164+ }
165+
122166TEST_LIST = {
123167 { "compress_small_string" , test_compress_small_string },
124168 { "decompress_small_string" , test_decompress_small_string },
125169 { "compress_empty_input" , test_compress_empty_input },
126170 { "decompress_invalid_data" , test_decompress_invalid_data },
127171 { "compress_decompress_large_data" , test_compress_decompress_large_data },
172+ { "decompress_unknown_size" , test_decompress_unknown_size },
128173 { NULL , NULL }
129174};
0 commit comments