110 Commits

Author SHA1 Message Date
  Andreas Romeyke ae3824fcac - fixed package name (removing underscore, because not allowed in *.deb) 2 days ago
  Andreas Romeyke b80a0d7bd8 - fixed version detection 2 weeks ago
  Andreas Romeyke 10634909b8 - using unsigned int 2 weeks ago
  Andreas Romeyke 8d8460ab77 - using unsigned int for testpos 2 weeks ago
  Andreas Romeyke 290099a3d0 - empty 2 weeks ago
  Andreas Romeyke 621025c6c2 - using memcpy instead strncpy 2 weeks ago
  Andreas Romeyke 7343d94a04 - reenabled calloc instead malloc 2 weeks ago
  art1pirat 0d99d0e059 - added hint to memory mapped I/O 3 weeks ago
  art1pirat 34e6d2bf01 - bugfix, if mmap detected, the macro _HAVE_MMAP should be defined 3 weeks ago
  art1pirat 7e8263e9ba - bugfix, malloc with correct size 3 weeks ago
  art1pirat 505323a0d0 - bugfix, malloc with correct size 3 weeks ago
  art1pirat 7f150e7ee4 -reduced RENDERMINSIZE 3 weeks ago
  art1pirat 6441c2c19b - rewritten secstrcat() using strbuff_t 3 weeks ago
  art1pirat 7b60d4fe20 - added strbuff_t type 3 weeks ago
  art1pirat c3ea1c7064 - removed xml renderer 3 weeks ago
  Andreas Romeyke 36bcd5261f - fixed loop 5 months ago
  Andreas Romeyke 4f566bccae - fixed index variable type 5 months ago
  Andreas Romeyke 4d9d00968b - fixed sign-warning in snprintf/printf 5 months ago
  Andreas Romeyke de0a07425a - replaced literal with constant macro 5 months ago
  Andreas Romeyke b815fcde22 - moved MINTAGS and MAXTAGS to check.h 5 months ago
  Andreas Romeyke 69e557b6fc - minor, invert condition 5 months ago
  Andreas Romeyke 61c7ad4c99 - minor fixes 5 months ago
  Andreas Romeyke cc23acf6d1 - reordered structures to avoid padding and to improve cache hits 5 months ago
  Andreas Romeyke 1ebe0b54a9 - added improved message if GNU11 support not detected 6 months ago
  Andreas Romeyke c8b2bb534c - fixed gcc format-truncation-warnings 6 months ago
  Andreas Romeyke aedd23bde0 - added fix to reenable MS Windows Support via MinGW 6 months ago
  Andreas Romeyke 27809aed3d - fixed to define _GNU_SOURCE only once 6 months ago
  Andreas Romeyke 21a547e34a - add some function static 6 months ago
  Andreas Romeyke ce987fe864 Merge branch 'development' 6 months ago
  Andreas Romeyke e28cd87825 - updated 6 months ago
  Andreas Romeyke 3846a3785e - fixed returncode evaluation in parse_icc_common_header() 6 months ago
  Andreas Romeyke 52af01406e - bugfix, using unsgned int for ifdbase 6 months ago
  Andreas Romeyke dfefe09669 - fixed tag marking 6 months ago
  Andreas Romeyke 5699d85f7a - fixed variable type 6 months ago
  Andreas Romeyke 0524eb6fce - removed duplicate entry 6 months ago
  Andreas Romeyke ab67340612 - removed macro SAVE_int2uint() 6 months ago
  Andreas Romeyke 519046eed6 - optimized includes 6 months ago
  Andreas Romeyke b08e735654 - optimized include 6 months ago
  Andreas Romeyke 2e53bd5646 - optimized include 6 months ago
  Andreas Romeyke bee151895b - optimized includes 6 months ago
  Andreas Romeyke 28435a0ea4 - check_tag_has_some_of_these_values() ues unsigned count now 6 months ago
  Andreas Romeyke f3c728e199 - optimized includes 6 months ago
  Andreas Romeyke ab0d38c10b - fixed cast warning 6 months ago
  Andreas Romeyke fbeeaa7f7e - fixed parameter using SAVE_int2uint() 6 months ago
  Andreas Romeyke 95a4c3b202 - fixed sign in for-loops 6 months ago
  Andreas Romeyke 3fbed4f8e9 - fixed warning aboz comparing float and unsigned int 6 months ago
  Andreas Romeyke 48bc97e48e - added macro SAVE_int2uint() and corresponding function 6 months ago
  Andreas Romeyke cf1243258f - changed count type from int to unsigned int in check_tag_has_valuelist() 6 months ago
  Andreas Romeyke fb2309da62 - added TIFF_ERROR to enum TIFFDataType 6 months ago
  Andreas Romeyke 28d9bf2838 - minor fix, use unsigned int 6 months ago
  Andreas Romeyke 28253d92a0 - minor fix, use constant 6 months ago
  Andreas Romeyke 8993d5097b - minor fix, enclosed macro argument in brackets 6 months ago
  Andreas Romeyke 0c77e076a4 - minor fix, use unsigned r 6 months ago
  Andreas Romeyke 388eb8f632 - minor fix, use unsigned short 6 months ago
  Andreas Romeyke 008d86299a - minor fix, enclosed macro argument in brackets 6 months ago
  Andreas Romeyke 3d6f10fd7b - using const for test_plausibility() 6 months ago
  Andreas Romeyke bb49e05ae3 - inverted order of check to improve performance 6 months ago
  Andreas Romeyke d121150517 - removed duplicate entry 6 months ago
  Andreas Romeyke 545e20103a - fixed cmake warnings 6 months ago
  Andreas Romeyke 47b0e38f73 - added cpack definitions to build install ready packages (Debian, RPM, TGZ, …) 6 months ago
  Andreas Romeyke 3bb8e273c7 - fix, cardinality should only be checked if both tags used 6 months ago
  Andreas Romeyke 399dab66ae - fixed tc 6 months ago
  Andreas Romeyke ef167c84d5 - added defaults 6 months ago
  Andreas Romeyke bc5aeed9fc - removed unused includes 6 months ago
  Andreas Romeyke d8f49012b2 - added check_cardinality_of_some_tags_are_equal() 6 months ago
  Andreas Romeyke 4f8142e702 - updated info/target for static compiled binaries 7 months ago
  Andreas Romeyke f31293a132 - fixed order to ensure CMAKE_C_FLAGS propagated correctly 7 months ago
  Andreas Romeyke d529f439a7 - added GNU extension bswap_xx() instead own implementation 7 months ago
  Andreas Romeyke ae8ee0474b - enabled LTO if supported 7 months ago
  Andreas Romeyke f29f00672b - added hardening compile- and link-options 1 year ago
  Andreas Romeyke 1c388123a8 - fixed tag SampleFormat (339) 1 year ago
  Andreas Romeyke 263fdf4237 Merge branch 'hotfix_cfg_sampleformat' 1 year ago
  Andreas Romeyke 3451e6eeb0 - fixed tag SampleFormat (339) 1 year ago
  Andreas Romeyke f69bc88b15 - removed duplicate code using switch-case shortcuts 1 year ago
  Andreas Romeyke b38842689d - minor, fixed warning about assignments without use 1 year ago
  Andreas Romeyke 6eae20b037 - removed duplicate code using switch-case shortcuts 1 year ago
  Andreas Romeyke 9d74604afb - removed duplicate include for unistd.h 1 year ago
  Andreas Romeyke fa499dd07a Merge branch 'development' of http://art1pirat.spdns.org/art1/checkit_tiff into development 1 year ago
  Andreas Romeyke d1478928d3 - bugfix, clean testdir/ after calling tests 1 year ago
  Andreas Romeyke b1ed86f994 - fixed indentation 1 year ago
  Andreas Romeyke cb7804d24b - integrated test-target into cmake config 1 year ago
  Andreas Romeyke cd8a4affcf - changed place of module declaration 1 year ago
  Andreas Romeyke 915f9d79d7 - enhanced doc 1 year ago
  Andreas Romeyke 4c75f7301b - init 1 year ago
  Andreas Romeyke 33fc15157d - added example of valid geotiff file 1 year ago
  Andreas Romeyke 8fb221bb8b - fixed tc count 1 year ago
  Andreas Romeyke 4d2775d110 - minor fixes 1 year ago
  Andreas Romeyke 2220d1775e - fixed peg to handle include correctly 1 year ago
  Andreas Romeyke 72df8ac46e - fixed grammar to handle include correctly 1 year ago
  Andreas Romeyke 375c75fde1 - replaced useless tifp_check() function by a macro. The macrocode will only be activated if the preprocessor option HARDEN is set 1 year ago
  Andreas Romeyke 12aa4a7e15 - fixed memleaks 1 year ago
  Andreas Romeyke 791fec2cb9 - fixed ICC version 1 year ago
  Andreas Romeyke 2d524a4ca6 - bugfix, order of linetype is important, now "include()" should be detected successfully 1 year ago
  Andreas Romeyke 95e34abca1 - minor fix (uint16 instead uint in loop), thanks to Nils F. 1 year ago
  Andreas Romeyke 3dceba838d - fixed links 1 year ago
  Andreas Romeyke 7c88f2f774 - bugfix, clean testdir/ after calling tests 1 year ago
  Andreas Romeyke a542a2da83 - fixed indentation 1 year ago
  Andreas Romeyke adad3775f4 Merge branch 'feature_cmake_based_tests' into development 1 year ago
  Andreas Romeyke 49cefbac30 - integrated test-target into cmake config 1 year ago
  Andreas Romeyke 50443e27ba - changed place of module declaration 1 year ago
  Andreas Romeyke 5d1088d292 - enhanced doc 1 year ago
  Andreas Romeyke 6520a8e350 - init 1 year ago
  Andreas Romeyke a6c503d6ad - added example of valid geotiff file 1 year ago
  Andreas Romeyke d9130c1c6f - fixed tc count 1 year ago
  Andreas Romeyke f81db5e8bf - minor fixes 1 year ago
  Andreas Romeyke 7785f0c397 - fixed peg to handle include correctly 1 year ago
  Andreas Romeyke 7e0f9f871c - fixed grammar to handle include correctly 1 year ago
  Andreas Romeyke 73582d317b - fixed ICC profile version 1 year ago
  Andreas Romeyke 0eb639e67d - replaced useless tifp_check() function by a macro. The macrocode will only be activated if the preprocessor option HARDEN is set 1 year ago
  Andreas Romeyke b51e61a45f - fixed memleaks 1 year ago
55 changed files with 1281 additions and 983 deletions
Split View
  1. +2
    -1
      FAQ
  2. +1
    -1
      README.1st_checkit
  3. +6
    -6
      README.compile
  4. +35
    -0
      README.testsuite
  5. +3
    -2
      example_configs/cit_tiff6_baseline_SLUB.cfg
  6. +4
    -3
      example_configs/cit_tiff6_geotiff_SLUB.cfg
  7. +231
    -0
      example_configs/cit_tiff_testcase.cfg
  8. +107
    -30
      src/CMakeLists.txt
  9. +3
    -12
      src/checkit_tiff.c
  10. +0
    -4
      src/checkit_tiff_risk.c
  11. +47
    -22
      src/headers/check.h
  12. +4
    -4
      src/headers/check_helper.h
  13. +2
    -4
      src/headers/check_renderer.h
  14. +34
    -36
      src/headers/config_parser.h
  15. +2
    -3
      src/headers/tiff.h
  16. +24
    -36
      src/helper/check_helper.c
  17. +4
    -2
      src/helper/check_print.c
  18. +0
    -13
      src/helper/check_renderer.c
  19. +48
    -49
      src/helper/check_tiffparse.c
  20. +76
    -73
      src/helper/renderer/check_renderer_ansi.c
  21. +58
    -55
      src/helper/renderer/check_renderer_default.c
  22. +0
    -131
      src/helper/renderer/check_renderer_xml.c
  23. +13
    -14
      src/ifdrules/check_all_IFDs_are_word_aligned.c
  24. +8
    -6
      src/ifdrules/check_all_geotiff_tags.c
  25. +3
    -4
      src/ifdrules/check_all_offsets_are_used_once_only.c
  26. +2
    -3
      src/ifdrules/check_all_offsets_are_word_aligned.c
  27. +5
    -4
      src/ifdrules/check_all_offsets_greater_zero.c
  28. +2
    -3
      src/ifdrules/check_has_only_one_ifd.c
  29. +3
    -4
      src/ifdrules/check_tagorder.c
  30. +40
    -0
      src/ifdrules/check_tags_with_corresponding_cardinality.c
  31. +6
    -0
      src/messages/msg_parser.c
  32. +161
    -139
      src/parser/config_dsl.grammar.c
  33. +24
    -5
      src/parser/config_dsl.grammar.peg
  34. +218
    -198
      src/parser/config_parser.c
  35. +18
    -20
      src/risk_analyzer/lst_offset_mappings.c
  36. +5
    -8
      src/tagrules/check_datetime.c
  37. +3
    -3
      src/tagrules/check_icc.c
  38. +2
    -2
      src/tagrules/check_notag.c
  39. +0
    -1
      src/tagrules/check_tag.c
  40. +7
    -7
      src/tagrules/check_tag_has_some_of_these_values.c
  41. +4
    -4
      src/tagrules/check_tag_has_valid_asciivalue.c
  42. +2
    -3
      src/tagrules/check_tag_has_valid_type.c
  43. +0
    -4
      src/tagrules/check_tag_has_value.c
  44. +3
    -4
      src/tagrules/check_tag_has_value_in_range.c
  45. +5
    -5
      src/tagrules/check_tag_has_value_matching_regex.c
  46. +14
    -8
      src/tagrules/check_tag_has_value_quiet.c
  47. +14
    -26
      src/tagrules/check_tag_has_valuelist.c
  48. +2
    -3
      src/tagrules/check_tag_quiet.c
  49. +17
    -12
      src/validate_icc/check_icc_header.c
  50. +4
    -3
      t/Testcall.pm
  51. +1
    -1
      t/test_config_examples.t
  52. +4
    -2
      t/test_grammar.t
  53. BIN
      tiffs_should_fail/minimal_different_cardinality_of_stripoffsets_and_stripbytescount.tiff
  54. BIN
      tiffs_should_pass/geotiff/minimal_geotiff.tiff
  55. BIN
      tiffs_should_pass/minimal_valid_with_icc.tiff

+ 2
- 1
FAQ View File

@ -61,10 +61,11 @@ A: No, the tool is optimized for very fast processing. On a NVME-based SSD it
cornercase, if you have a broken TIFF with very large IFDs. Because
checkit_tiff tries to find all errors in a given TIFF file it does not use
early aborts than some other tools.
You could also try the memory mapped I/O, which should be very fast on supported filesystems.
Q: I have a fully destroyed TIFF because checkit_tiff reports IFD errors. Is
there any chance to repair the file?
A: You could give "fixit_tiff" a try:
https://github.com/SLUB-digitalpreservation/fixit_tiff
http://andreas-romeyke.de/software.html#_fixit_tiff
This project comes with some helper tools to find lost IFDs and could
fix some typical errors in broken TIFF files.

+ 1
- 1
README.1st_checkit View File

@ -35,7 +35,7 @@ HINTS
** https://github.com/EasyinnovaSL/DPFManager/tree/develop/src/test/resources/
** or https://github.com/openpreserve/jhove/tree/junit_tests/examples/tiff/badfiles
* please do not hesitate to contact me.
* to *repair* TIFFs, you could give "fixit_tiff" a try: https://github.com/SLUB-digitalpreservation/fixit_tiff
* to *repair* TIFFs, you could give "fixit_tiff" a try: http://andreas-romeyke.de/software.html#_fixit_tiff
== Compile ==


+ 6
- 6
README.compile View File

@ -5,7 +5,7 @@
########################################################
mkdir build
cd build
cmake ../src/ -DCMAKE_C_FLAGS="-W -Wall -Wextra -ansi -pedantic -O3 -Wno-unused-function -fstack-check"
cmake ../src/ -DCMAKE_C_FLAGS="-W -Wall -Wextra -ansi -pedantic -O3 -flto -Wno-unused-function -fstack-check -fstack-protector-strong -Wformat -Werror=format-security"
make
###
# if you want to allow preferred CMM type "LINO", you should use the cmake-call
@ -24,14 +24,14 @@ make
########################################################
# cmake ../src/ -DCMAKE_C_COMPILER=$(which gcc)
# cmake ../src/ -DCMAKE_C_FLAGS="-O0 -p -g"
# cmake ../src/ -DCMAKE_C_COMPILER=$(which clang-3.5) -DCMAKE_C_FLAGS="-Oz -pedantic"
# cmake ../src/ -DCMAKE_C_COMPILER=$(which clang-7) -DCMAKE_C_FLAGS="-Oz -pedantic"
#
########################################################
# example SANITIZE options
########################################################
#
# SANITIZE with clang++
# cmake ../src/ -DCMAKE_C_COMPILER=/usr/bin/clang-3.5 -DCMAKE_C_FLAGS="-O0 -g -fsanitize=address -fno-omit-frame-pointer"
# cmake ../src/ -DCMAKE_C_COMPILER=/usr/bin/clang-8 -DCMAKE_C_FLAGS="-O0 -g -fsanitize=address -fno-omit-frame-pointer"
# make
# ASAN_OPTIONS=detect_leaks=1 ./checkit_tiff ...
#
@ -45,14 +45,14 @@ make
# example STATIC options
########################################################
#
# cmake ../src/ -DCMAKE_EXE_LINKER_FLAGS="-static-libgcc" -DCMAKE_FIND_LIBRARY_SUFFIXES=".a" -DPCRE_LIBRARY=/usr/lib/x86_64-linux-gnu/libpcre.a
# cmake ../src/ -DSTATIC=1 -DCMAKE_C_FLAGS="-O3 -s -flto -Wno-unused-function -fstack-check -fstack-protector-strong -Wformat -Werror=format-security"
#
########################################################
# example CLANG-TIDY
########################################################
# cmake ../src/ -DCMAKE_C_CLANG_TIDY:STRING="clang-tidy;-checks=-*,readability-*" -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DCMAKE_C_COMPILER=/usr/bin/clang-3.8 -DCMAKE_C_FLAGS="-O0 -g -fsanitize=address -fno-omit-frame-pointer"
# cmake ../src/ -DCMAKE_C_CLANG_TIDY:STRING="clang-tidy;-checks=-*,readability-*" -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DCMAKE_C_COMPILER=/usr/bin/clang-8 -DCMAKE_C_FLAGS="-O0 -g -fsanitize=address -fno-omit-frame-pointer"
# make
# run-clang-tidy-3.8.py -clang-tidy-binary /usr/bin/clang-tidy-3.8
# run-clang-tidy-8.py -clang-tidy-binary /usr/bin/clang-tidy-8
#
#
########################################################


+ 35
- 0
README.testsuite View File

@ -0,0 +1,35 @@
########################################################
the directory tiffs_should_pass/ contains TIFF-files that should generally be
valid. This does not mean that they have to be valid against every profile.
Rudimentary tests are available in the t/ directory to check the correctness of
checkit_tiff using Perl.
It needs the following Perl modules (in brackets the debian module):
* Data::Printer (libdata-printer-perl)
* Exporter (perl-base)
* File::Path (perl-base)
* File::Slurp (libfile-slurp-perl)
* File::Spec (perl-base)
* IPC::Open3 (perl-base)
* POSIX (perl-base)
* Test::More (perl-modules-XXX with XXX as Perl-version )
in cmake the test-target is enabled by default, you could run it via:
$> cmake ../src
$> make
$> make test
If you want to call it manually, you should try this instead:
$> cd t/
$> perl -I./ test_grammar.t && echo "fine!"
$> perl -I./ test_config_examples.t && echo "fine!"
$> perl -I./ test_should_pass.t && echo "fine!"
$> perl -I./ test_should_fail.t && echo "fine!"
the return code for all these runs should be zero and result in message "fine!"

+ 3
- 2
example_configs/cit_tiff6_baseline_SLUB.cfg View File

@ -186,8 +186,9 @@ mode(enable_ifd_checks)
# 338 0152 ExtraSamples Description of extra components.
#338; optional; range(0-2)
# Sampleformat
339; optional; only(1)
# Sampleformat, default 1, list length = value of SamplesPerPixel (277)
339; optdepends(277.1); only(1)
339; optdepends(277.3); ntupel(1,1,1)
# 700 02BC XMP XML packet containing XMP metadata.
700; optional; any


+ 4
- 3
example_configs/cit_tiff6_geotiff_SLUB.cfg View File

@ -184,6 +184,10 @@ mode(enable_deep_geotiff_checks)
# 338 0152 ExtraSamples Description of extra components.
#338; optional; range(0-2)
# Sampleformat, default 1, list length = value of SamplesPerPixel (277)
339; optdepends(277.1); only(1)
339; optdepends(277.3); ntupel(1,1,1)
# 700 02BC XMP XML packet containing XMP metadata.
700; optional; any
@ -228,6 +232,3 @@ mode(enable_deep_geotiff_checks)
#42113; optional; any
#Georeferenced Additional Tags
# Testing lfulg-geo-data
# 339 SampleFormat
339; optional; any

+ 231
- 0
example_configs/cit_tiff_testcase.cfg View File

@ -0,0 +1,231 @@
#0000000000000000000000
#
#0000000000000000000
#000000000000000000000000000000
#000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000000000000000000000000000
#0000000000000000000000000000000000000000000000000000000000000000000000000
#00000000000
mode(baseline)
mode(enable_type_checks)
mode(enable_offset_checks)
mode(enable_ifd_checks)
mode(enable_deep_geotiff_checks)
#0000
#00000000000000000000000
#0000
#00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
256;mandatory; range(0, 0000000090)
#0000000000000000000000000000000000000000000000000000000000000000
257; mandatory; range(0, 0000000090)
#00000000000000000000000000000000000000000000000000000
#000000000000000000000000000000000000000000000000000000000
#00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
258; optdepends(262.0); logical_or(0,00,00)
258; optdepends(262.1); logical_or(1,00, 0)
258; depends(262.0); logical_or(ntupel(0,0,0), ntupel(00,00,00))
258; depends(262.0); logical_or(0, 0)
#0000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000000
259; mandatory; only(1)
#0000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
262; mandatory; range(0, 2)
#000000000000000000000000000000000000000000000000000000000000000000000
273; mandatory; any
#0000000000000000000000000000000000000000000000000000000000000
#00000000000000000000000
#0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
270; depends(262.0); only(0)
277; optdepends(262.1); only(1)
277; optdepends(262.0); only(0)
#0000000000000000000000000000000000000000000000000000
278; mandatory; range(0, 0000007000)
#00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#0000000000000000000000000000000000000000000000000000000000
279; mandatory; any
#000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
282; mandatory; range(000, 4000)
#0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
283; mandatory; range(000, 4000)
#00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
296; mandatory; only(2)
#0000
#0000000000000000
#0000
#0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
254; optional; logical_or(0, 0)
#000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#00000000000000000000000000
#00000000000000000000000000000000000000000000000000000000000000000000000
#0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#00000000000000000000000000
#000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000
#0000000000000000000000000000000000000000000000000000000000000000000000
#0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000
#000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000000000000000000000000000000000000000
266; optional; only(1)
#000000000000000000000000000
260; optional; printascii
#0000000000000000000000000000000000000000000000000000000000000000000000000000
270; optional; printascii
#0000000000000000000000000000000000000000
270; optional; printascii
#0000000000000000000000000000000000000000000000000
270; optional; printascii
#000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000000000000000000000000000000000000000000000000000000000
274; optional; only(1)
#000000000000000000000000000000000000000000000000000000000000000000000000
280; optional; any
#0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
280; optional; any
#00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
284; optional; only(1)
#000000000000000000000000000000000000000000000000000000000000000000000000
#00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000
#0000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000
#00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
290; optdepends(260.0); range(0, 0)
290; optdepends(260.0); range(0, 0)
#0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
290; optdepends(260.0); any
290; optdepends(260.0); any
#00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
297; optional; ntupel(0,1)
#00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
300; optional; printascii
#000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
300; optional; datetime
#00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000
#000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000
#0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000000000
#00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#00000000000000000000000
300;optional;any
#000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000000000000000000000000000000000
#000000000000000000000000000000
#00000000000000000000000000000000000000000000000000000000000000000000000000
#0000000000000000000000000000000000000000000000000000000
#0000000000000000000
#00000000000000000000
#00000000000000000000
300;optional;any
#000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#00000000000000000
#00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#0000000000000000000000000000000000000000000000000000000
#0000000000000000000000000
#00000000000000000000000000000000000000000000000000
700;optional;any
#000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
300;optional;printascii
#0000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000000000000000000000000000000000000000
#00000000000000000000
#0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#0000000000000000000000000000000000000000000000000000000000000000000000
#00000000000000000000
#0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
300;optional;any
#0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
600;optdepends(260.0);iccprofile
34675;optdepends(262.1);iccprofile
34675;optdepends(262.0);iccprofile
#000000000000
#000000000000000000000000000000000
33550;mandatory;any
#000000000000000000000000
33922;mandatory;any
#00000000000000000000000000000000000000000000000000000000000000000000000000000000
#000000000000000000000
#000000000000000000000000000000000
34735;mandatory;any
#000000000000000000000000000000000
700;optional;any
#000000000000000000000000
300;optional;printascii
#00000000000000
300;optional;any
#00000000000000000000
400;optional;any
#000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#00000000000000000000
#00000000000000000000000000000
#00000000000000000000000
#00000000000000000
300;optional;any

+ 107
- 30
src/CMakeLists.txt View File

@ -1,11 +1,13 @@
cmake_minimum_required (VERSION 2.6)
cmake_minimum_required (VERSION 3.9.4)
project (checkit_tiff)
include_directories("${PROJECT_SOURCE_DIR}/headers")
include_directories("${PROJECT_SOURCE_DIR}/validate_icc")
include (CheckSymbolExists)
include (CheckFunctionExists)
include(CheckIPOSupported)
file( GLOB checkit_tiff_SOURCES
file( GLOB checkit_tiff_SOURCES
"${PROJECT_SOURCE_DIR}/tagrules/*.c"
"${PROJECT_SOURCE_DIR}/ifdrules/*.c"
"${PROJECT_SOURCE_DIR}/messages/*.c"
@ -22,7 +24,7 @@ file( GLOB checkit_tiff_risk_SOURCES
"${PROJECT_SOURCE_DIR}/helper/check_tiffparse.c"
"${PROJECT_SOURCE_DIR}/messages/*.c"
"${PROJECT_SOURCE_DIR}/risk_analyzer/*.c"
)
)
#
# Make a version file containing the current version from git.
@ -35,27 +37,48 @@ execute_process( COMMAND git describe --long --tags --dirty --always OUTPUT_VARI
add_definitions(-DVERSION="${BUILD_BRANCH}_${BUILD_TAG}")
add_definitions(-DREPO_REVISION="${REPO_REVISION}")
check_ipo_supported(RESULT LTO_IS_SUPPORTED OUTPUT LTO_CHECK_ERROR)
if (LTO_IS_SUPPORTED)
message(STATUS "IPO / LTO enabled")
set(INTERPROCEDURAL_OPTIMIZATIONS TRUE)
else()
message(STATUS "IPO / LTO unsupported: <${LTO_CHECK_ERROR}>")
endif()
# add default CFLAGS
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong -Wformat -Werror=format-security")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro -fPIE")
# Check for compatibility with gnu11
# Compile with gnu11 support.
include(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG("-std=gnu11" COMPILER_SUPPORTS_GNU11)
if(COMPILER_SUPPORTS_GNU11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
else()
message(STATUS "Your compiler (${CMAKE_C_COMPILER}) has no gnu11 support. If you are using clang on Apple OS X, please switch to gcc (version > 4.7) which is compliant with the C11 standard.")
message(STATUS "Your compiler (${CMAKE_C_COMPILER}) has no gnu11 support.")
message(STATUS "If you are using clang on Apple OS X, please switch to gcc (version > 4.7) which is compliant with the C11 standard.")
message(STATUS "If you are using MinGW or compile under MS Windows, the code could compile, but without any warranty and without any support!")
endif()
if(WIN32)
add_definitions(-D__WIN32__=1)
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
SET(BUILD_SHARED_LIBRARIES OFF)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set(BUILD_SHARED_LIBRARIES OFF)
# needed to increase default stack, because Win7 has only 1MB
SET(CMAKE_EXE_LINKER_FLAGS "-static -Wl,--stack,20000000")
set(CMAKE_EXE_LINKER_FLAGS "-static -Wl,--stack,20000000")
add_definitions(-DPCRE_STATIC)
add_definitions(-D_POSIX_C_SOURCE=200809L)
# FIXME: needed for MingW only
add_definitions(-D_GNU_SOURCE=1)
endif(WIN32)
endif()
if(STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set(BUILD_SHARED_LIBRARIES OFF)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
add_definitions(-DPCRE_STATIC)
endif()
add_executable(checkit_tiff checkit_tiff.c ${checkit_tiff_SOURCES})
add_executable(checkit_check_config checkit_check_config.c ${checkit_tiff_SOURCES})
@ -63,44 +86,98 @@ add_executable(checkit_tiff_risk checkit_tiff_risk.c ${checkit_tiff_risk_SOURCES
set(CMAKE_EXTRA_INCLUDE_FILES tiff.h)
#libpcre
#find_package(LIBPCRE REQUIRED)
FIND_PATH(PCRE_INCLUDE_DIR NAMES pcre.h)
FIND_LIBRARY(PCRE_LIBRARY NAMES pcre)
INCLUDE(FindPackageHandleStandardArgs)
find_path(PCRE_INCLUDE_DIR NAMES pcre.h)
find_library(PCRE_LIBRARY NAMES pcre)
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE DEFAULT_MSG PCRE_LIBRARY PCRE_INCLUDE_DIR)
if (PCRE_FOUND)
SET(PCRE_LIBRARIES ${PCRE_LIBRARY})
SET(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${PCRE_INCLUDE_DIR})
else(PCRE_FOUND)
MESSAGE(FATAL_ERROR "No PCRE library found, add $PCRE_INCLUDE_DIR manually")
endif(PCRE_FOUND)
set(PCRE_LIBRARIES ${PCRE_LIBRARY})
if (STATIC)
set(PCRE_LIBRARIES ${PCRE_LIBRARIES} -lpthread)
endif()
set(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR})
include_directories(${PCRE_INCLUDE_DIR})
else()
message(FATAL_ERROR "No PCRE library found, add $PCRE_INCLUDE_DIR manually")
endif()
#find mmap
CHECK_FUNCTION_EXISTS(mmap _HAVE_MMAP)
CHECK_FUNCTION_EXISTS(munmap _HAVE_MUNMAP)
IF(_HAVE_MMAP AND _HAVE_MUNMAP)
MESSAGE(INFO "mmap found")
SET(_HAVE__MMAP 1)
ENDIF()
if(_HAVE_MMAP AND _HAVE_MUNMAP)
message(INFO "mmap found")
set(_HAVE__MMAP 1)
add_definitions(-D_HAVE_MMAP)
endif()
TARGET_LINK_LIBRARIES(checkit_tiff ${PCRE_LIBRARIES})
TARGET_LINK_LIBRARIES(checkit_check_config ${PCRE_LIBRARIES})
TARGET_LINK_LIBRARIES(checkit_tiff_risk)
target_link_libraries(checkit_tiff ${PCRE_LIBRARIES})
target_link_libraries(checkit_check_config ${PCRE_LIBRARIES})
target_link_libraries(checkit_tiff_risk)
install( TARGETS checkit_tiff
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
)
install(DIRECTORY
)
install(DIRECTORY
../example_configs
../tiffs_should_fail
../tiffs_should_pass
../tiffs_should_pass
DESTINATION share/checkit_tiff/
)
)
file( GLOB README_FILES "../README*" "../FAQ" "../LICENSE" "../TODO" "../BUGS")
install(FILES ${README_FILES} DESTINATION share/checkit_tiff/)
include(FindPerl)
if (PERL_FOUND)
enable_testing()
set(T_DIR ${PROJECT_SOURCE_DIR}/../t )
add_test(NAME grammar COMMAND ${PERL_EXECUTABLE} -I ${T_DIR} test_grammar.t WORKING_DIRECTORY ${T_DIR} )
add_test(NAME config COMMAND ${PERL_EXECUTABLE} -I ${T_DIR} test_config_examples.t WORKING_DIRECTORY ${T_DIR} )
add_test(NAME validfiles COMMAND ${PERL_EXECUTABLE} -I ${T_DIR} test_should_pass.t WORKING_DIRECTORY ${T_DIR} )
add_test(NAME invalidfiles COMMAND ${PERL_EXECUTABLE} -I ${T_DIR} test_should_fail.t WORKING_DIRECTORY ${T_DIR} )
else()
message(WARN "for testsuite an installed Perl is needed")
endif()
# CPACK definitions
include(InstallRequiredSystemLibraries)
set (CPACK_PACKAGE_VENDOR "Andreas Romeyke")
string(REGEX REPLACE "^v([0-9]+).*" "\\1" MAJOR_VERSION ${BUILD_TAG})
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" MINOR_VERSION ${BUILD_TAG})
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" PATCH_VERSION ${BUILD_TAG})
message( "BUILDTAG (after) : '${BUILD_TAG}'")
message( "MAJOR VERSION: ${MAJOR_VERSION}")
message( "MINOR VERSION: ${MINOR_VERSION}")
message( "PATCH VERSION: ${PATCH_VERSION}")
set (CPACK_PACKAGE_NAME "checkit-tiff")
set (CPACK_PACKAGE_VERSION_MAJOR ${MAJOR_VERSION})
set (CPACK_PACKAGE_VERSION_MINOR ${MINOR_VERSION})
set (CPACK_PACKAGE_VERSION_PATCH ${PATCH_VERSION})
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/../LICENSE")
set (CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/../README.1st_checkit")
set (CPACK_GENERATOR "TGZ;STGZ;TZ;DEB;RPM")
#set (CPACK_GENERATOR "DEB")
set (CPACK_PACKAGE_CONTACT "Andreas Romeyke checkit_tiff@andreas-romeyke.de")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "checkit-tiff is a policy-oriented conformance checker for baseline TIFFs")
set(CPACK_PACKAGE_DESCRIPTION "checkit-tiff is a conformance checker for baseline TIFFs (with various extensions). It works in different way than other tools. Instead to use a hardcoded rule set with predefined values, you are able to define tags and corresponding values more fine granulary. The rulesets are human readable and could be adapted to own needs.")
# Debian related
#set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc (>= 6.0)")
set(CPACK_DEBIAN_PACKAGE_SECTION "misc")
set(CPACK_DEBIAN_COMPRESSION_TYPE "xz")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set (CPACK_DEBIAN_PACKAGE_VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION})
#set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE amd64)
set (CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
set (CPACK_DEBIAN_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}
${CPACK_PACKAGE_DESCRIPTION}")
set (CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
include(CPack)

+ 3
- 12
src/checkit_tiff.c View File

@ -8,20 +8,14 @@
#include "config_parser.h"
#include "check.h"
#include "check_helper.h"
#include "check_renderer.h"
#include <unistd.h>
#include <assert.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifdef __unix__
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#else
/* #include <sys\stat.h> */
#include <sys/stat.h>
@ -111,7 +105,7 @@ int main (int argc, char * argv[]) {
int c;
int flag_check_directory=UNFLAGGED;
int flag_use_memorymapped_io=UNFLAGGED;
while ((c = getopt (argc, argv, "chmdx:q")) != -1) {
while ((c = getopt(argc, argv, "chmdx:q")) != -1) {
switch (c)
{
case 'h': /* help */
@ -120,9 +114,6 @@ int main (int argc, char * argv[]) {
case 'c': /* colorize output */
set_renderer_to_ansi();
break;
case 'x': /* xml output */
set_renderer_to_xml( optarg);
break;
case 'd': /* check directory */
flag_check_directory = FLAGGED;
printf("\nCheck all files in given directory\n");
@ -139,7 +130,7 @@ int main (int argc, char * argv[]) {
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
return (-1);
}
else*/ if (isprint (optopt)) {
else*/ if (isprint(optopt)) {
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
return (-1);
}


+ 0
- 4
src/checkit_tiff_risk.c View File

@ -10,14 +10,10 @@
#include "check_helper.h"
#include <ctype.h>
#ifdef __unix__
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#else
/* #include <sys\stat.h> */
#include <sys/stat.h>
#endif
#include <unistd.h>
#define FLAGGED 1
#define UNFLAGGED 0


+ 47
- 22
src/headers/check.h View File

@ -8,6 +8,9 @@
#ifndef _FIXIT_TIFF_CHECK
#define _FIXIT_TIFF_CHECK
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdlib.h>
#include "tiff.h"
#include <stdio.h>
@ -19,7 +22,13 @@ typedef int thandle_t;
typedef uint16 tag_t;
typedef enum{ true=1, false=0 } bool_t;
typedef unsigned short int bool_t;
static const bool_t false = 0;
static const bool_t true = 1;
/* MINTAGS - MAXTAGS is range of possible existing TAG numbers */
#define MINTAGS 254U
#define MAXTAGS 65536U
typedef enum{ is_memmap, is_filep } ct_ioflag_t ; /* flag */
@ -28,15 +37,15 @@ typedef enum{ has_sorted_tags, has_unsorted_tags, unknown_tag_order } tagorder_t
typedef struct ctiff_s {
ct_ioflag_t ioflag;
tagorder_t tagorder;
int tag_cache[65536];
char *filename; /* filename */
uint8 * streamp; /* address of memory-mapped tif stream */
uint8 * actual_streamp;
uint32 streamlen; /* length of tif stream/file (in bytes) */
thandle_t fd; /* filedescriptor */
uint32 ifd0pos; /* offset in tif stream (in bytes) */
uint16 ifd0c; /* count of tags in first ifd */
int isbyteswapped; /* true if BigEndian */
char *filename; /* filename */
bool_t isbyteswapped; /* true if BigEndian */
int tag_cache[MAXTAGS];
} ctiff_t;
typedef enum{
@ -63,9 +72,9 @@ typedef enum{
} rm_type_t;
typedef struct retmsg_s {
rm_type_t rm_type;
char * rm_msg;
struct retmsg_s * next;
rm_type_t rm_type;
} retmsg_t;
#define ICC_ERROR_OFFSET 100
@ -129,18 +138,15 @@ typedef enum {
parser_logical_combine_open, /* if fc_logicalcombine was called first (no error) */
parser_logical_combine_close, /* if fc_logicalcombine was called first (no error) */
tagerror_offset_is_zero,
ifderror_different_cardinality,
} returncode_t;
typedef struct ret_s {
returncode_t returncode;
char * value_found;
int logical_or_count;
char * value_found;
} ret_t;
typedef struct ifd_entry_s {
uint32 count; /* count of data */
TIFFDataType datatype;
@ -218,19 +224,37 @@ typedef struct mem_map_entry_s {
} mem_map_entry_t;
typedef struct mem_map_s {
mem_map_entry_t * base_p;
int count;
mem_map_entry_t * base_p;
uint32 max_len; /* TIFF length */
int max_entries;
uint32 max_len; /* TIFF length */
} mem_map_t;
#define MAXSTRLEN 1024
#define EXPECTSTRLEN 500
#define VALUESTRLEN 500
#define TIFFAILSTRLEN (EXPECTSTRLEN + VALUESTRLEN)
#define MAXRESULT 200000
returncode_t tifp_check( ctiff_t * ctif);
#define MAXRESULT 48000U
#ifdef HARDEN
#define TIFP_CHECK( ctif, ret ) \
if (NULL == ctif) { ret.returncode = code_error_ctif_empty; ret.value_found="code error, empty ctif-structure"; return ret; };\
if ((0 > ctif->fd) && (NULL == ctif->streamp)) {\
if (0 > ctif->fd) { ret.returncode = code_error_filedescriptor_empty; ret.value_found="empty filedescriptor"; return ret; };\
if (NULL == ctif->streamp) { ret.returncode = code_error_streampointer_empty; ret.value_found="empty stream pointer"; return ret; }; \
}
#else
#define TIFP_CHECK( ctif, ret ) ;
#endif
typedef struct strbuff_s {
size_t bufsize;
size_t pos;
char * bufpos;
char * buf;
} strbuff_t;
//returncode_t tifp_check( ctiff_t * ctif);
/*
ret_t tif_returns(tag_t tag, const char* expected, const char* value);
ret_t tif_fails_tag(tag_t tag, const char* expected, const char* value);
@ -243,15 +267,15 @@ ret_t tif_no_tag(tag_t tag);
ret_t _empty_result();
*/
const char * float2str(float v);
const char* tag2str(tag_t tag);
const char* int2str(int v);
const char* frac2str(int d, int n);
const char* range2str(int d, int n);
char* float2str(float v);
char* tag2str(tag_t tag);
char* int2str(int v);
char* frac2str(int d, int n);
char* range2str(int d, int n);
off_t ct_seek(ctiff_t * ctif, off_t pos, int whence);
ssize_t ct_read(ctiff_t * ctif, void *buf, size_t count);
ret_t check_tag_has_some_of_these_values( ctiff_t * ctif, tag_t tag, int count, const unsigned int * values);
ret_t check_tag_has_valuelist( ctiff_t * ctif, tag_t tag, int count, const unsigned int * values);
ret_t check_tag_has_some_of_these_values( ctiff_t * ctif, tag_t tag, unsigned int count, const unsigned int * values);
ret_t check_tag_has_valuelist( ctiff_t * ctif, tag_t tag, unsigned int count, const unsigned int * values);
ret_t check_tag_has_value_in_range(ctiff_t * ctif, tag_t tag, unsigned int a, unsigned int b);
ret_t check_tag_has_value(ctiff_t * ctif, tag_t tag, unsigned int value);
ret_t check_tag_has_value_quiet(ctiff_t * ctif, tag_t tag, unsigned int expected_value);
@ -270,6 +294,7 @@ ret_t check_all_offsets_are_used_once_only(ctiff_t * ctif);
ret_t check_all_offsets_are_greater_zero(ctiff_t * ctif);
ret_t check_all_IFDs_are_word_aligned(ctiff_t * ctif);
ret_t check_all_geotiff_tags( ctiff_t * ctif);
ret_t check_cardinality_of_some_tags_are_equal( ctiff_t * ctif);
mem_map_t * scan_mem_map(ctiff_t * ctif) ;
void print_mem_map( mem_map_t * memmap_p);


+ 4
- 4
src/headers/check_helper.h View File

@ -33,7 +33,7 @@ ret_t TIFFGetFieldLONG(ctiff_t * ctif, const tag_t tag, uint32 ** result_long_p,
ret_t TIFFGetFieldSHORT(ctiff_t * ctif, const tag_t tag, uint16 ** result_short_p, uint32 * result_countp);
ret_t TIFFGetFieldRATIONAL(ctiff_t * ctif, const tag_t tag, float ** result_float_p, uint32 * result_countp);
ret_t read_offsetdata(ctiff_t * ctif, const uint32 address, const uint32 count, const uint16 datatype, offset_t * result_offsetp, ret_t * ret_p);
char * secstrcat (char * dest, const char * src, const size_t * maxsize_p);
strbuff_t * secstrcat (strbuff_t * dest, const char * src);
ctiff_t * initialize_ctif( const char * tiff_file, ct_ioflag_t );
void free_ctif( ctiff_t * ctif);
uint32 get_ifd0_pos( ctiff_t * ctif);
@ -49,7 +49,7 @@ void __clean_render_pipeline( retmsg_t ** pointer );
#define GET_EMPTY_RET(ret) \
ret_t ret; \
ret.value_found = NULL; \
ret.logical_or_count = 0; \
ret.returncode = should_not_occur;
(ret).value_found = NULL; \
(ret).logical_or_count = 0; \
(ret).returncode = should_not_occur;
#endif

+ 2
- 4
src/headers/check_renderer.h View File

@ -13,18 +13,16 @@
/* 65536 Tags a 256 chars message + 100 Messages */
/* #define RENDERSIZE (65536*256 + 100*256) */
#define RENDERMINSIZE (1024)
#define RENDERMINSIZE (512)
#define RENDERMAXSIZE (33554432)
typedef enum{ render_default, render_ansi, render_xml} render_type;
typedef enum{ render_default, render_ansi} render_type;
typedef enum{ within_valid, within_error, within_file, within_summaryerror, within_harderror } render_context_t;
const char * renderer ( const retmsg_t * ret );
void set_renderer_to_ansi();
void set_renderer_to_xml(const char *);
void set_renderer_to_quiet();
const char * renderer_ansi ( const retmsg_t * ret, short int );
const char * renderer_default ( const retmsg_t * ret, short int );
const char * renderer_xml ( const retmsg_t * ret, const char * xml );
#endif


+ 34
- 36
src/headers/config_parser.h View File

@ -1,7 +1,7 @@
/* rule based checks if given TIFF is a specific baseline TIFF
*
*
* author: Andreas Romeyke, 2015
* licensed under conditions of libtiff
* licensed under conditions of libtiff
* (see http://libtiff.maptools.org/misc.html)
*
*/
@ -24,15 +24,11 @@ typedef enum {
mode_enable_deep_geotiff_checks=16,
} modes_t;
/* MINTAGS - MAXTAGS is range of possible existing TAG numbers */
#define MINTAGS 254
#define MAXTAGS 65536
#define MAXINCLUDEDEPTH 1
/* the stack size depends on count of rules and count of numbers, in general
* 65536 should be enough. Otherwise you need to increase it */
#define MAXSTACKDEPTH 65536
#define MAXSTACKDEPTH 65536u
typedef enum {
fc_true,
fc_false,
@ -58,30 +54,32 @@ typedef enum {
fc_internal_logic_combine_close,
fc_all_offsets_are_not_zero,
fc_all_geotiff_tags_have_same_count_of_values,
fc_check_cardinality,
fc_dummy
} function_t;
#define INTERNALSTACKDEPTH 10
#define INTERNALSTACKDEPTH 8u
typedef struct internal_entry_s {
int lineno;
bool_t is_precondition;
tag_t tag;
function_t function;
values_t val_stack[INTERNALSTACKDEPTH];
const char * regex_stack[INTERNALSTACKDEPTH];
short int i_stackp;
short int val_stackp;
short int regex_stackp;
unsigned int i_stack[INTERNALSTACKDEPTH];
int i_stackp;
int val_stackp;
int regex_stackp;
values_t val_stack[INTERNALSTACKDEPTH];
char * regex_stack[INTERNALSTACKDEPTH];
} internal_entry_t;
typedef struct full_res_s {
int lineno;
tag_t tag;
function_t function;
returncode_t returncode;
tag_t tag;
char * expected_value;
char * found_value;
returncode_t returncode;
} full_res_t;
typedef struct parser_state_s {
@ -90,33 +88,33 @@ typedef struct parser_state_s {
int valuelist;
tag_t tag;
tag_t tagref;
values_t val_stack[MAXSTACKDEPTH];
const char * regex_stack[MAXSTACKDEPTH];
reference_t any_reference;
requirements_t req;
unsigned int i_stack[MAXSTACKDEPTH];
int i_stackp;
int val_stackp;
int regex_stackp;
int called_tags[MAXTAGS];
int mode;
int logical_elements;
short int i_stackp;
short int val_stackp;
FILE * stream;
reference_t any_reference;
const char * regex_string;
int includedepth;
full_res_t result_stack[MAXRESULT];
int result_stackp;
int exe_stackp;
internal_entry_t exe_stack[MAXSTACKDEPTH];
int mode;
bool_t within_logical_or;
int logical_elements;
short int regex_stackp;
int called_tags[MAXTAGS];
full_res_t result_stack[MAXRESULT];
values_t val_stack[MAXSTACKDEPTH];
char * regex_stack[MAXSTACKDEPTH];
unsigned int i_stack[MAXSTACKDEPTH];
internal_entry_t exe_stack[MAXSTACKDEPTH];
} parser_state_t;
void _helper_push_result(full_res_t res);
full_res_t _helper_pop_result();
void _helper_mark_top_n_results(int n, returncode_t type);
full_res_t _helper_get_nth(int n);
ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep);
void set_parse_error(char * msg, char * yytext);
static void _helper_push_result(full_res_t res);
static full_res_t _helper_pop_result();
static void _helper_mark_top_n_results(int n, returncode_t type);
static full_res_t _helper_get_nth(int n);
static ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep);
static void set_parse_error(char * msg, char * yytext);
void execute_plan (ctiff_t * ctif);
void print_plan ();
ret_t print_plan_results (retmsg_t *);
@ -124,9 +122,9 @@ void clean_plan ();
void parse_plan ();
void parse_plan_via_stream (FILE * file);
void parse_plan_via_file (const char * cfg_file);
void add_default_rules_to_plan();
void set_include( const char * );
static void add_default_rules_to_plan();
static void set_include( const char * );
void exe_printstack_human_readable ();
void result_push(full_res_t);
static void result_push(full_res_t);
#endif
/* _FIXIT_TIFF_CONFIG_PARSER */

+ 2
- 3
src/headers/tiff.h View File

@ -139,7 +139,8 @@ typedef enum {
TIFF_IFD = 13, /* %32-bit unsigned integer (offset) */
TIFF_LONG8 = 16, /* BigTIFF 64-bit unsigned integer */
TIFF_SLONG8 = 17, /* BigTIFF 64-bit signed integer */
TIFF_IFD8 = 18 /* BigTIFF 64-bit unsigned integer (offset) */
TIFF_IFD8 = 18, /* BigTIFF 64-bit unsigned integer (offset) */
TIFF_ERROR = 0,
} TIFFDataType;
/*
@ -662,8 +663,6 @@ typedef enum {
#define EXIFTAG_SHARPNESS 41994 /* Sharpness */
#define EXIFTAG_DEVICESETTINGDESCRIPTION 41995 /* Device settings description */
#define EXIFTAG_SUBJECTDISTANCERANGE 41996 /* Subject distance range */
#define EXIFTAG_GAINCONTROL 41991 /* Gain control */
#define EXIFTAG_GAINCONTROL 41991 /* Gain control */
#define EXIFTAG_IMAGEUNIQUEID 42016 /* Unique image ID */
#endif /* _TIFF_ */


+ 24
- 36
src/helper/check_helper.c View File

@ -6,73 +6,63 @@
*
*/
#define _GNU_SOURCE
#include <math.h>
#include "check.h"
#include "check_helper.h"
#include "check_renderer.h"
#include <unistd.h>
#include <sys/stat.h>
#include <assert.h>
#include <fcntl.h>
#include <string.h>
#ifndef _WIN32
#include <byteswap.h>
#endif
#ifdef _WIN32
#define bswap_16 _byteswap_ushort
#define bswap_32 _byteswap_ulong
#endif
/*
#define DEBUG
*/
/* dest should not exceed maxsize */
char * secstrcat (char * dest, const char * src, const size_t * maxsize_p) {
if (NULL == dest) {
fprintf(stderr, "internal error, dest is NULL!\n");
exit(EXIT_FAILURE);
}
if (NULL == src) {
} else {
assert(NULL != maxsize_p);
size_t maxsize = *maxsize_p;
size_t destsize = strnlen(dest, maxsize);
size_t srclen = strnlen(src, maxsize);
size_t maxdest = destsize + srclen;
if (maxdest < maxsize-1) {
strncat( dest, src, srclen);
} else {
fprintf(stderr, "max string length of dest + src (%zu + %zu) exceeds maxsize %zu\n", destsize, srclen, maxsize);
strbuff_t * secstrcat (strbuff_t * dest, const char * src) {
if (NULL != src) {
assert(NULL != dest );
size_t srclen = strlen(src);
if ((dest->pos + srclen) > dest->bufsize) {
fprintf(stderr, "max string length of dest + src (%zu + %zu) exceeds maxsize %zu\n", dest->pos, srclen, dest->bufsize);
exit(EXIT_FAILURE);
}
memcpy(dest->bufpos, src, srclen);
dest->bufpos += srclen;
// fprintf(stderr, "DEBUG: dest->pos=%zu, src len=%zu", dest->pos, srclen);
dest->pos += srclen;
// fprintf(stderr, " new dest_pos=%zu\n", dest->pos);
}
return dest;
}
const char * float2str(float v) {
char * float2str(float v) {
char array[VALUESTRLEN];
snprintf(array, sizeof(array), "%f", v);
return strdup(array);
}
const char* int2str(int v) {
char* int2str(int v) {
char array[VALUESTRLEN];
snprintf(array, sizeof(array), "%i", v);
return strdup(array);
}
const char* frac2str(int d, int n) {
char* frac2str(int d, int n) {
char array[VALUESTRLEN];
snprintf(array, sizeof(array), "%i/%i", d, n);
return strdup(array);
}
void TIFFSwabShort(uint16 *a) {
uint16 b = ((*a & 0xff) << 8) | ((*a >> 8) & 0xff);
*a=b;
*a = bswap_16( *a );
}
void TIFFSwabLong(uint32 *a) {
uint8 b0 = (*a) & 0xff;
uint8 b1 = (*a >> 8) & 0xff;
uint8 b2 = (*a >> 16) & 0xff;
uint8 b3 = (*a >> 24) & 0xff;
uint32 b = (b0 << 24) | (b1 << 16) | (b2 << 8) | b3;
*a=b;
*a = bswap_32( *a );
}
long long fsize(int fd) {
@ -85,12 +75,10 @@ long long fsize(int fd) {
ret_t set_value_found_ret (ret_t * rp, const char * msg) {
assert( NULL != rp);
assert( NULL != msg);
rp->value_found=malloc(sizeof(char) * VALUESTRLEN);
rp->value_found=calloc(VALUESTRLEN, sizeof(char));
if (NULL == rp->value_found) {
rp->returncode=could_not_allocate_memory;
} else {
memset(rp->value_found, '\0', VALUESTRLEN);
// printf("DEBUG='%s'\n", msg);
strncpy(rp->value_found, msg, VALUESTRLEN-1);
// printf("DEBUG2='%s'\n", rp->value_found);
}


+ 4
- 2
src/helper/check_print.c View File

@ -6,7 +6,6 @@
*
*/
#define _GNU_SOURCE
#include <assert.h>
#include <string.h>
@ -44,7 +43,8 @@ returncode_t __add_to_render_pipeline_via_strncpy (retmsg_t ** pointer, const ch
exit (could_not_allocate_memory);
// return could_not_allocate_memory;
}
strncpy(msg, src, src_len );
//strncpy(msg, src, src_len );
memcpy(msg, src,src_len);
actual_render->next = next;
actual_render->next->rm_msg = msg;
actual_render->next->rm_type = src_type;
@ -72,11 +72,13 @@ void __clean_render_pipeline( retmsg_t ** pointer ) {
}
}
/*
returncode_t tifp_check( ctiff_t * ctif) {
if (NULL == ctif) { return code_error_ctif_empty; };
if (0 > ctif->fd) { return code_error_filedescriptor_empty; };
if (NULL == ctif->streamp) { return code_error_streampointer_empty; };
return should_not_occur;
}
*/
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 smarttab expandtab :*/

+ 0
- 13
src/helper/check_renderer.c View File

@ -6,19 +6,11 @@
*
*/
#define _GNU_SOURCE
#include <math.h>
#include "check.h"
#include "check_helper.h"
#include "check_renderer.h"
#include <unistd.h>
#include <assert.h>
#include <fcntl.h>
#include <string.h>
render_type render_engine=render_default;
short int is_quiet = 1;
const char * xmlfile = NULL;
void set_renderer_to_quiet() {
is_quiet=0;
@ -29,15 +21,10 @@ void set_renderer_to_ansi() {
render_engine=render_ansi;
}
}
void set_renderer_to_xml( const char * given_xmlfile) {
render_engine=render_xml;
xmlfile = given_xmlfile;
}
const char * renderer ( const retmsg_t * ret ) {
// call debug renderer
switch (render_engine) {
case render_xml: return renderer_xml( ret, xmlfile);
case render_ansi: return renderer_ansi( ret, is_quiet );
default: return renderer_default( ret, is_quiet );
}


+ 48
- 49
src/helper/check_tiffparse.c View File

@ -6,28 +6,20 @@
*
*/
#define _GNU_SOURCE
#include <math.h>
#include "check.h"
#include "check_helper.h"
#include "msg_tiffparse.h"
#include <unistd.h>
#include <assert.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>
#ifdef _HAVE__MMAP
#ifdef _HAVE_MMAP
#include <sys/mman.h>
#include <errno.h>
#endif
#include <errno.h>
/*
#define DEBUG
*/
off_t ct_seek(ctiff_t * ctif, off_t pos, int whence) {
#ifdef _HAVE__MMAP
#ifdef _HAVE_MMAP
switch (ctif->ioflag) {
case is_filep:
assert(ctif->fd >= 0);
@ -49,7 +41,7 @@ off_t ct_seek(ctiff_t * ctif, off_t pos, int whence) {
ctif->actual_streamp = ctif->streamp + ctif->streamlen + pos;
break;
}
int testpos = ctif->actual_streamp - ctif->streamp;
uint32 testpos = ctif->actual_streamp - ctif->streamp;
if ( testpos > ctif->streamlen) {
/*
* fprintf(stderr, "seek offset outside of file on new pos=%i (filesize=%i)\n", testpos, ctif->streamlen);
@ -80,7 +72,7 @@ ssize_t ct_read(ctiff_t * ctif, void *buf, size_t count) {
perror("Buffer buf is a NULL-pointer");
exit( EXIT_FAILURE );
}
#ifdef _HAVE__MMAP
#ifdef _HAVE_MMAP
switch (ctif->ioflag) {
case is_filep:
// TODO: add checks if seek will be outside of file!!!
@ -91,7 +83,7 @@ ssize_t ct_read(ctiff_t * ctif, void *buf, size_t count) {
assert( ctif->streamp != NULL);
assert( ctif->actual_streamp != NULL);
int testpos = (ctif->actual_streamp+count) - (ctif->streamp);
uint32 testpos = (ctif->actual_streamp+count) - (ctif->streamp);
if ( testpos > ctif->streamlen) {
/*
* fprintf(stderr, "read offset outside of file on new pos=%i (filesize=%i)\n", testpos, ctif->streamlen);
@ -133,7 +125,7 @@ int TIFFGetRawTagListIndex(ctiff_t * ctif, tag_t tag) { /* find n-th entry in IF
if (0 == count) { return -1; }
tag_t last = TIFFGetRawTagListEntry(ctif, 0);
ctif->tag_cache[last] = 0;
for (uint i= 1; i < count; i++) {
for (uint16 i= 1; i < count; i++) {
tag_t current = TIFFGetRawTagListEntry( ctif, i );
if (last >= current) {
ctif->tagorder=has_unsorted_tags;
@ -149,8 +141,8 @@ int TIFFGetRawTagListIndex(ctiff_t * ctif, tag_t tag) { /* find n-th entry in IF
//------------------------------------------------------------------------------
ret_t check_tag_has_fvalue(ctiff_t * ctif, tag_t tag, float value) {
GET_EMPTY_RET(ret)
tifp_check( ctif);
GET_EMPTY_RET(ret);
TIFP_CHECK( ctif, ret);
float * valp = NULL;
uint32 found;
@ -161,7 +153,9 @@ ret_t check_tag_has_fvalue(ctiff_t * ctif, tag_t tag, float value) {
ret.returncode=is_valid;
return ret;
} else {
ret = set_value_found_ret(&ret, float2str(val)) ;
char * msg = float2str(val);
ret = set_value_found_ret(&ret, msg ) ;
free ( msg );
ret.returncode = tagerror_value_differs;
}
}
@ -170,8 +164,8 @@ ret_t check_tag_has_fvalue(ctiff_t * ctif, tag_t tag, float value) {
//------------------------------------------------------------------------------
ret_t check_tag_has_u16value(ctiff_t * ctif, tag_t tag, uint16 value) {
GET_EMPTY_RET(ret)
tifp_check( ctif);
GET_EMPTY_RET(ret);
TIFP_CHECK( ctif, ret);
uint16 * valp = NULL;
uint32 found;
@ -182,7 +176,9 @@ ret_t check_tag_has_u16value(ctiff_t * ctif, tag_t tag, uint16 value) {
ret.returncode=is_valid;
return ret;
} else {
ret = set_value_found_ret(&ret, int2str(val));
char * msg = int2str(val);
ret = set_value_found_ret(&ret, msg );
free ( msg );
ret.returncode = tagerror_value_differs;
return ret;
}
@ -194,9 +190,8 @@ ret_t check_tag_has_u16value(ctiff_t * ctif, tag_t tag, uint16 value) {
//------------------------------------------------------------------------------
ret_t check_tag_has_u32value(ctiff_t * ctif, tag_t tag, uint32 value) {
GET_EMPTY_RET(ret)
tifp_check( ctif);
GET_EMPTY_RET(ret);
TIFP_CHECK( ctif, ret);
uint32 * valp = NULL;
uint32 found;
@ -207,7 +202,9 @@ ret_t check_tag_has_u32value(ctiff_t * ctif, tag_t tag, uint32 value) {
ret.returncode=is_valid;
return ret;
} else {
ret = set_value_found_ret(&ret, int2str(val));