diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ef160fac29bbfc927115ab3212c54d2aaac39698..23193f02a9c10efa8c2492ece321745228bd1c89 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -85,6 +85,8 @@ jobs: pip install meson ninja pytest sudo apt-get update sudo apt-get install gcc-mingw-w64 wine64 + - name: Update PATH for wine + run: echo "/usr/lib/wine" >> "$GITHUB_PATH" - name: mingw cross-compilation and testing run: | meson setup \ @@ -101,7 +103,6 @@ jobs: name: MinGW cross compile Testlog path: builddir_cross_win/meson-logs/testlog.txt - mingw-build-test: runs-on: windows-latest defaults: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..deaf686ad3392b6d80c2d9cea987fe6c8cf04d9c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,31 @@ +repos: + - repo: 'https://github.com/pre-commit/pre-commit-hooks' + rev: v5.0.0 + hooks: + - id: trailing-whitespace + args: + - '--markdown-linebreak-ext=md' + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: check-case-conflict + - repo: 'https://github.com/codespell-project/codespell' + rev: v2.3.0 + hooks: + - id: codespell + - repo: 'https://github.com/jorisroovers/gitlint' + rev: v0.19.1 + hooks: + - id: gitlint + - repo: 'https://github.com/dloidolt/pre-commit-checkpatch' + rev: v0.1.0 + hooks: + - id: checkpatch-files + args: + - '--fix-inplace' + - '--show-types' + - '--ignore=SPDX_LICENSE_TAG,PREFER_DEFINED_ATTRIBUTE_MACRO,INLINE' + - repo: 'https://github.com/bbastin/pre-commit-meson.git' + rev: v1.0.0 + hooks: + - id: meson-test 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 f4938dc15cb7e7f866ec7abab22baabbe1300a5d..8dc453d699a5c105b339ba9aaeca1d1dbbee8dfe 100644 --- a/programs/cmp_io.c +++ b/programs/cmp_io.c @@ -18,6 +18,7 @@ * @warning this part of the software is not intended to run on-board on the ICU. */ +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -553,7 +554,8 @@ int cmp_mode_parse(const char *cmp_mode_str, enum cmp_mode *cmp_mode) } } return -1; - } else { + } + { uint32_t read_val; if (atoui32(cmp_mode_str, cmp_mode_str, &read_val)) @@ -916,7 +918,8 @@ static int parse_info(FILE *fp, struct cmp_info *info) fprintf(stderr, "%s: Error read in cmp_mode_used.\n", PROGRAM_NAME); return -1; - } else { + } + { uint32_t tmp; if (atoui32(token1, token2, &tmp)) @@ -1443,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 bae19f9d93878f1a37552b06ece78c03c4a6840d..3d0e7f2b9ad386d9255fd93c4308ca5999010f6e 100644 --- a/programs/cmp_tool.c +++ b/programs/cmp_tool.c @@ -122,14 +122,14 @@ static const struct option long_options[] = { static const char *output_prefix = DEFAULT_OUTPUT_PREFIX; /* if non zero additional RDCU parameters are included in the compression - * configuration and decompression information files */ + * configuration and decompression information files + */ static int add_rdcu_pars; /* if non zero generate RDCU setup packets */ static int rdcu_pkt_mode; -/* file name of the last compression information file to generate parallel RDCU - * setup packets */ +/* file name of the last compression information file to generate parallel RDCU setup packets */ static const char *last_info_file_name; /* option flags for file IO */ @@ -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; @@ -628,8 +633,8 @@ static int guess_cmp_pars(struct rdcu_cfg *rcfg, struct cmp_par *chunk_par, if (cmp_is_error(result)) return -1; - else - cmp_size_bit = 8 * result; + + cmp_size_bit = 8 * result; printf("DONE\n"); printf("Write the guessed compression chunk parameters to file %s.par ... ", output_prefix); diff --git a/subprojects/unity.wrap b/subprojects/unity.wrap index 29246ac476339b20e6f4abcece97ca3009978f67..39e04d80d9347a0d13baefc570cdf8d4f9ad6d3b 100644 --- a/subprojects/unity.wrap +++ b/subprojects/unity.wrap @@ -1,8 +1,8 @@ [wrap-file] -directory = Unity-2.6.0 -source_url = https://github.com/ThrowTheSwitch/Unity/archive/refs/tags/v2.6.0.tar.gz -source_filename = Unity-2.6.0.tar.gz -source_hash = aa4c9fb1ae5fc5242f914c65f3557e817e40cb37f04a31e5ff76d1ab89dbf674 +directory = Unity-2.6.1 +source_url = https://github.com/ThrowTheSwitch/Unity/archive/refs/tags/v2.6.1.tar.gz +source_filename = Unity-2.6.1.tar.gz +source_hash = b41a66d45a6b99758fb3202ace6178177014d52fc524bf1f72687d93e9867292 [provide] unity = unity_dep diff --git a/test/cmp_tool/cmp_tool_integration_test.py b/test/cmp_tool/cmp_tool_integration_test.py index c4856c42e75bebe36d93e89184e1d38037bfa6fc..3f7e00418dabaa60380f71183369920a23caf977 100755 --- a/test/cmp_tool/cmp_tool_integration_test.py +++ b/test/cmp_tool/cmp_tool_integration_test.py @@ -1311,7 +1311,6 @@ def test_model_fiel_erros(): returncode, stdout, stderr = call_cmp_tool( " -c "+cfg_file_name+" -d "+data_file_name + " -m "+model_file_name+" -o "+output_prefix) assert(returncode == EXIT_FAILURE) - print(stdout) assert(stdout == CMP_START_STR_CMP + "Importing configuration file %s ... DONE\n" % (cfg_file_name) + "Importing data file %s ... DONE\n" % (data_file_name) + @@ -1332,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'