diff --git a/CHANGELOG.md b/CHANGELOG.md index de799aa6163b9ed0710e9c956bcb768042e9e791..443309e2fd35f0bf3c6cfc2c32c7a814f69885a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All notable changes to this project will be documented in this file. +## [0.14] - 16-01-2025 +### Added +- check for model file size mismatch errors + ## [0.13] - 08-11-2024 ### Added - added chunk-specific compression parameter guessing functionality diff --git a/meson.build b/meson.build index d31ceca42a5e71c6cf88a879a3300e8d1fd94eb7..f91a1b79c444a392bcb75d6ab9c78f08ef3bd1c3 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('cmp_tool', 'c', - version : '0.13', + version : '0.14', meson_version : '>= 0.63', license : 'GPL-2.0', default_options : [ diff --git a/programs/cmp_io.c b/programs/cmp_io.c index 653f8fe8f0487dea89e2e2f3b676664f5261d927..8dc453d699a5c105b339ba9aaeca1d1dbbee8dfe 100644 --- a/programs/cmp_io.c +++ b/programs/cmp_io.c @@ -1446,10 +1446,10 @@ ssize_t read_file_data(const char *file_name, enum cmp_type cmp_type, switch (cmp_type) { case CMP_TYPE_RDCU: - err = be_to_cpu_data_type(buf, (uint32_t)size, DATA_TYPE_IMAGETTE); + err = be_to_cpu_data_type(buf, buf_size, DATA_TYPE_IMAGETTE); break; case CMP_TYPE_CHUNK: - err = be_to_cpu_chunk(buf, (uint32_t)size); + err = be_to_cpu_chunk(buf, buf_size); break; case CMP_TYPE_ERROR: default: diff --git a/programs/cmp_tool.c b/programs/cmp_tool.c index a0f1180618b20f9ab4bafb1957ba1345fbf834ca..3d0e7f2b9ad386d9255fd93c4308ca5999010f6e 100644 --- a/programs/cmp_tool.c +++ b/programs/cmp_tool.c @@ -511,6 +511,11 @@ int main(int argc, char **argv) model_size, io_flags); if (size < 0) goto fail; + if (size != (ssize_t)model_size) { + fprintf(stderr, "%s: %s: Error: Model file size does not match original data size.\n", PROGRAM_NAME, model_file_name); + goto fail; + } + printf("DONE\n"); rcfg.model_buf = input_model_buf; diff --git a/test/cmp_tool/cmp_tool_integration_test.py b/test/cmp_tool/cmp_tool_integration_test.py index 5f80ab1eb9e86f703ca232e01b51d9e24d895537..3f7e00418dabaa60380f71183369920a23caf977 100755 --- a/test/cmp_tool/cmp_tool_integration_test.py +++ b/test/cmp_tool/cmp_tool_integration_test.py @@ -1331,6 +1331,33 @@ def test_model_fiel_erros(): del_file(output_prefix+"_upmodel.dat") +def test_decmp_model_fiel_original_size_miss_match(): + cmp_data = b'8000000d000029000004097ce800cbd5097ce800cbfe00010108d01001000000001001001110078700' + to_large_model = b'111111111111' # should be 4 byte large in normal case + output_prefix = 'model_file_to_large' + cmp_data_file_name = 'binary_cmp_data.cmp' + model_file_name = 'to_large_model.dat' + + try: + with open(cmp_data_file_name, 'wb') as f: + f.write(bytes.fromhex(cmp_data.decode())) + + with open(model_file_name, 'wb') as f: + f.write(bytes.fromhex(to_large_model.decode())) + + returncode, stdout, stderr = call_cmp_tool( + " --binary -d "+cmp_data_file_name + " -m " + model_file_name + " -o "+output_prefix) + assert(returncode == EXIT_FAILURE) + assert(stdout == CMP_START_STR_DECMP + + "Importing compressed data file %s ... DONE\n" % (cmp_data_file_name) + + "Importing model file %s ... FAILED\n" % (model_file_name)) + assert(stderr == "cmp_tool: %s: Error: Model file size does not match original data size.\n" % (model_file_name)) + + finally: + del_file(cmp_data_file_name) + del_file(model_file_name) + + def test_rdcu_pkt(): # generate test data data = '00 01 00 02 00 03 00 04 00 05 \n'