Skip to content
Snippets Groups Projects
Commit 3321f1d8 authored by Dominik Loidolt's avatar Dominik Loidolt
Browse files

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
parent 9e6d2911
No related branches found
No related tags found
1 merge request!35Add model file size mismatch check and update version to 0.14
# Changelog # Changelog
All notable changes to this project will be documented in this file. 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 ## [0.13] - 08-11-2024
### Added ### Added
- added chunk-specific compression parameter guessing functionality - added chunk-specific compression parameter guessing functionality
......
project('cmp_tool', 'c', project('cmp_tool', 'c',
version : '0.13', version : '0.14',
meson_version : '>= 0.63', meson_version : '>= 0.63',
license : 'GPL-2.0', license : 'GPL-2.0',
default_options : [ default_options : [
......
...@@ -1446,10 +1446,10 @@ ssize_t read_file_data(const char *file_name, enum cmp_type cmp_type, ...@@ -1446,10 +1446,10 @@ ssize_t read_file_data(const char *file_name, enum cmp_type cmp_type,
switch (cmp_type) { switch (cmp_type) {
case CMP_TYPE_RDCU: 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; break;
case CMP_TYPE_CHUNK: case CMP_TYPE_CHUNK:
err = be_to_cpu_chunk(buf, (uint32_t)size); err = be_to_cpu_chunk(buf, buf_size);
break; break;
case CMP_TYPE_ERROR: case CMP_TYPE_ERROR:
default: default:
......
...@@ -511,6 +511,11 @@ int main(int argc, char **argv) ...@@ -511,6 +511,11 @@ int main(int argc, char **argv)
model_size, io_flags); model_size, io_flags);
if (size < 0) if (size < 0)
goto fail; 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"); printf("DONE\n");
rcfg.model_buf = input_model_buf; rcfg.model_buf = input_model_buf;
......
...@@ -1331,6 +1331,33 @@ def test_model_fiel_erros(): ...@@ -1331,6 +1331,33 @@ def test_model_fiel_erros():
del_file(output_prefix+"_upmodel.dat") 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(): def test_rdcu_pkt():
# generate test data # generate test data
data = '00 01 00 02 00 03 00 04 00 05 \n' data = '00 01 00 02 00 03 00 04 00 05 \n'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment