From 23f8a606240feafd9b29db32f1cdbb060469c0ed Mon Sep 17 00:00:00 2001 From: Dominik Loidolt <dominik.loidolt@univie.ac.at> Date: Tue, 12 Nov 2024 13:20:03 +0100 Subject: [PATCH 1/5] Add pre-commit configuration file This commit introduces a pre-commit configuration file (.pre-commit-config.yaml) to ensure code quality and consistency by automatically running various checks and fixes before commits are finalized. Quick start =========== 1. Install pre-commit Before you can run hooks, you need to have the pre-commit package manager installed. Using pip: pip install pre-commit 2. Install the git hook scripts run: pre-commit install to set up the git hook scripts Now pre-commit will run automatically on git commit! 3. (optional) Run against all the files It's usually a good idea to run the hooks against all of the files when adding new hooks (usually pre-commit will only run on the changed files during git hooks): pre-commit run --all-files For more information see https://pre-commit.com --- .pre-commit-config.yaml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..deaf686 --- /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 -- GitLab From 92cf172df49dfbae776dadef90b7a21a7787dc2f Mon Sep 17 00:00:00 2001 From: Dominik Loidolt <dominik.loidolt@univie.ac.at> Date: Thu, 16 Jan 2025 11:39:22 +0100 Subject: [PATCH 2/5] Update Unity to version 2.6.1 --- subprojects/unity.wrap | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/subprojects/unity.wrap b/subprojects/unity.wrap index 29246ac..39e04d8 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 -- GitLab From 9e6d2911e13cab246b66e8bf500542217e4ef280 Mon Sep 17 00:00:00 2001 From: Dominik Loidolt <dominik.loidolt@univie.ac.at> Date: Thu, 16 Jan 2025 12:00:55 +0100 Subject: [PATCH 3/5] Refactor: Improve coding style consistency - cmp_io.c: Added missing header includes and adjusted brace usage for better readability. - cmp_tool.c: Improved comment formatting and removed redundant else blocks. - cmp_tool_integration_test.py: Removed unnecessary print statements. --- programs/cmp_io.c | 7 +++++-- programs/cmp_tool.c | 10 +++++----- test/cmp_tool/cmp_tool_integration_test.py | 1 - 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/programs/cmp_io.c b/programs/cmp_io.c index f4938dc..653f8fe 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)) diff --git a/programs/cmp_tool.c b/programs/cmp_tool.c index bae19f9..a0f1180 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 */ @@ -628,8 +628,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/test/cmp_tool/cmp_tool_integration_test.py b/test/cmp_tool/cmp_tool_integration_test.py index c4856c4..5f80ab1 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) + -- GitLab From 3321f1d85cd491721cd6ba7a79bfe042acd2e7c7 Mon Sep 17 00:00:00 2001 From: Dominik Loidolt <dominik.loidolt@univie.ac.at> Date: Thu, 16 Jan 2025 12:11:27 +0100 Subject: [PATCH 4/5] Add model file size mismatch check and update version to 0.14 - Added a check to verify model file size matches original data size and report errors - Fix buffer overflow in `read_file_data` when file size exceeds `buf_size` - Updated version to 0.14 --- CHANGELOG.md | 4 ++++ meson.build | 2 +- programs/cmp_io.c | 4 ++-- programs/cmp_tool.c | 5 ++++ test/cmp_tool/cmp_tool_integration_test.py | 27 ++++++++++++++++++++++ 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de799aa..443309e 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 d31ceca..f91a1b7 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 653f8fe..8dc453d 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 a0f1180..3d0e7f2 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 5f80ab1..3f7e004 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' -- GitLab From 0702169ee975d3126dd83b3b9ff57228d9487846 Mon Sep 17 00:00:00 2001 From: Dominik Loidolt <dominik.loidolt@univie.ac.at> Date: Thu, 16 Jan 2025 12:58:17 +0100 Subject: [PATCH 5/5] test.yml: fix wine PATH for MinGW build --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ef160fa..23193f0 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: -- GitLab