135 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
  Andreas Romeyke 3acfe8708a - fixed warnings 1 year ago
  Andreas Romeyke 3004fe71b0 - removed unused variable 1 year ago
  Andreas Romeyke 9d9b2361ce - simplified code 1 year ago
  Andreas Romeyke bd4aeb3ea3 - removed DEBUG 1 year ago
  Andreas Romeyke d782ad71f5 - enhanced __add_to_render_pipeline_via_strncpy() signature by strlen 1 year ago
  Andreas Romeyke cdfc28aa82 - fixed warning 1 year ago
  Andreas Romeyke e761e8f062 - minor, removed unused variable assignment 1 year ago
  Andreas Romeyke e59cfb3cdf - fixed variable type, uint16 instead int should be used 1 year ago
  Andreas Romeyke cc40d81f6f - removed deadcode 1 year ago
  Andreas Romeyke 4f66bdfb1d - using fabsf() instead fabs(), because float 1 year ago
  Andreas Romeyke 0cbd57d4fe - using secstrcat() correctly, using RENDERMINSIZE and RENDERMAXSIZE 1 year ago
  Andreas Romeyke 793bc9a8ca - simplified secstrcat() 1 year ago
  Andreas Romeyke 2060ea2708 - fixed assert 1 year ago
  Andreas Romeyke 47fa5e10d0 - added brackets 1 year ago
  Andreas Romeyke 6cec9f4040 - comment cleanup 1 year ago
  Andreas Romeyke f9a02cbd1e - improved readability 1 year ago
  Andreas Romeyke a23b7fe178 - secured macro 1 year ago
  Andreas Romeyke dd2d031b62 - fixed size calculation bug, size_t instead int is used now 1 year ago
  Andreas Romeyke a6412c60e4 - minor lint fix 1 year ago
  Andreas Romeyke ee3247428b - changed signature of __clean_render_pipeline() 1 year ago
  Andreas Romeyke 0dc97cbab1 - added hint if segfault on highly corrupted tiff files 1 year ago
  Andreas Romeyke 7ae9990a85 - refactoring, improved code 1 year ago
  Andreas Romeyke bdeaecb3e1 - fix to supress wrong "#line 0" 2 years ago
  Andreas Romeyke 467824caa8 - fixed shadowed variable warnings 2 years ago
  Andreas Romeyke 53dbeb5f6d - fixed size warnings 2 years ago
56 changed files with 1444 additions and 1388 deletions
Split View
  1. +2
    -1
      FAQ
  2. +1
    -1
      README.1st_checkit
  3. +7
    -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. +1
    -1
      src/Makefile
  10. +17
    -27
      src/checkit_tiff.c
  11. +10
    -18
      src/checkit_tiff_risk.c
  12. +55
    -30
      src/headers/check.h
  13. +10
    -9
      src/headers/check_helper.h
  14. +5
    -6
      src/headers/check_renderer.h
  15. +34
    -36
      src/headers/config_parser.h
  16. +2
    -3
      src/headers/tiff.h
  17. +27
    -48
      src/helper/check_helper.c
  18. +30
    -229
      src/helper/check_print.c
  19. +0
    -13
      src/helper/check_renderer.c
  20. +98
    -82
      src/helper/check_tiffparse.c
  21. +80
    -77
      src/helper/renderer/check_renderer_ansi.c
  22. +62
    -59
      src/helper/renderer/check_renderer_default.c
  23. +0
    -131
      src/helper/renderer/check_renderer_xml.c
  24. +13
    -14
      src/ifdrules/check_all_IFDs_are_word_aligned.c
  25. +13
    -11
      src/ifdrules/check_all_geotiff_tags.c
  26. +3
    -4
      src/ifdrules/check_all_offsets_are_used_once_only.c
  27. +3
    -4
      src/ifdrules/check_all_offsets_are_word_aligned.c
  28. +6
    -5
      src/ifdrules/check_all_offsets_greater_zero.c
  29. +2
    -3
      src/ifdrules/check_has_only_one_ifd.c
  30. +4
    -5
      src/ifdrules/check_tagorder.c
  31. +40
    -0
      src/ifdrules/check_tags_with_corresponding_cardinality.c
  32. +6
    -0
      src/messages/msg_parser.c
  33. +161
    -187
      src/parser/config_dsl.grammar.c
  34. +24
    -5
      src/parser/config_dsl.grammar.peg
  35. +236
    -216
      src/parser/config_parser.c
  36. +18
    -20
      src/risk_analyzer/lst_offset_mappings.c
  37. +5
    -8
      src/tagrules/check_datetime.c
  38. +8
    -9
      src/tagrules/check_icc.c
  39. +2
    -2
      src/tagrules/check_notag.c
  40. +0
    -1
      src/tagrules/check_tag.c
  41. +7
    -7
      src/tagrules/check_tag_has_some_of_these_values.c
  42. +4
    -4
      src/tagrules/check_tag_has_valid_asciivalue.c
  43. +2
    -3
      src/tagrules/check_tag_has_valid_type.c
  44. +0
    -4
      src/tagrules/check_tag_has_value.c
  45. +3
    -4
      src/tagrules/check_tag_has_value_in_range.c
  46. +7
    -5
      src/tagrules/check_tag_has_value_matching_regex.c
  47. +14
    -8
      src/tagrules/check_tag_has_value_quiet.c
  48. +14
    -26
      src/tagrules/check_tag_has_valuelist.c
  49. +2
    -3
      src/tagrules/check_tag_quiet.c
  50. +17
    -12
      src/validate_icc/check_icc_header.c
  51. +4
    -3
      t/Testcall.pm
  52. +1
    -1
      t/test_config_examples.t
  53. +4
    -2
      t/test_grammar.t
  54. BIN
      tiffs_should_fail/minimal_different_cardinality_of_stripoffsets_and_stripbytescount.tiff
  55. BIN
      tiffs_should_pass/geotiff/minimal_geotiff.tiff
  56. 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 ==


+ 7
- 6
README.compile View File

@ -1,10 +1,11 @@
# You need an installed cmake
########################################################
# compiling under linux
# HINT: use "-fstack-check" if you expect highly corrupted TIFF-files
########################################################
mkdir build
cd build
cmake ../src/ -DCMAKE_C_FLAGS="-W -Wall -Wextra -ansi -pedantic -O2 -Wno-unused-function"
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
@ -23,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 ...
#
@ -44,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)

+ 1
- 1
src/Makefile View File

@ -34,7 +34,7 @@ parser/config_dsl.grammar.c: parser/config_dsl.grammar.peg
# produce parser via PEG
%.c: %.peg
peg $< > $@
peg -P $< > $@
-include version.mk


+ 17
- 27
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>
@ -35,7 +29,7 @@ void help () {
printf ("checkit_tiff\n");
printf ("\tversion: %s\n", VERSION);
printf ("\trevision: %s\n", REPO_REVISION);
printf("licensed under conditions of libtiff (see http://libtiff.maptools.org/misc.html)\n\n");
printf ("licensed under conditions of libtiff (see http://libtiff.maptools.org/misc.html)\n\n");
printf ("call it with:\n");
printf ("\tcheckit_tiff [-c|-h|-m|-d|-q] <configfile> <tifffile> [<tifffile>]\n");
printf ("\nwhere <tifffile> is the tiff file (or directory) to be validated\n");
@ -71,19 +65,19 @@ int check_specific_tiff_file( const char * tiff_file, int use_memmapped) {
res = parse_header_and_endianess( ctif );
if (res.returncode != is_valid) {
assert(NULL != res.value_found);
__add_to_render_pipeline_via_strncpy(&actual_render, res.value_found, rm_hard_error);
__add_to_render_pipeline_via_strncpy(&actual_render, "", rm_endtiff);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN(res.value_found), rm_hard_error);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN(""), rm_endtiff);
//printf("res.val='%s'\n", res.value_found);
goto renderer_exit;
}
}
uint32 offset;
res=get_first_IFD(ctif, &offset);
if (res.returncode != is_valid) {
assert(NULL != res.value_found);
__add_to_render_pipeline_via_strncpy(&actual_render, res.value_found, rm_hard_error);
__add_to_render_pipeline_via_strncpy(&actual_render, "", rm_endtiff);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN(res.value_found), rm_hard_error);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN(""), rm_endtiff);
goto renderer_exit;
}
}
execute_plan(ctif);
res = print_plan_results( actual_render);
renderer_exit:
@ -91,7 +85,7 @@ renderer_exit:
const char * render_result_string = renderer( render_pipeline );
printf("%s\n", render_result_string);
/* free all entries of render pipeline */
__clean_render_pipeline( render_pipeline );
__clean_render_pipeline( &render_pipeline );
free((void *) render_result_string);
}
free_ctif( ctif );
@ -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);
}
@ -161,7 +152,7 @@ int main (int argc, char * argv[]) {
}
const char *cfg_file=argv[optind];
printf("cfg_file=%s\n", cfg_file);
int is_valid = 0;
int are_valid = 0;
int index_of_tiff_file_or_dir = optind+1;
do {
const char *tiff_file_or_dir=argv[index_of_tiff_file_or_dir++];
@ -172,8 +163,7 @@ int main (int argc, char * argv[]) {
/* iterate through all files */
size_t len = strlen( tiff_file_or_dir);
char tiff_dir [ len+1 ];
strncpy(tiff_dir, tiff_file_or_dir, len);
tiff_dir[ len ] = 0;
strcpy(tiff_dir, tiff_file_or_dir);
DIR *dir;
/* remove trailing / */
char *dirsuffix = strrchr(tiff_dir, '/');
@ -199,9 +189,9 @@ int main (int argc, char * argv[]) {
exit(EXIT_FAILURE);
}
if(attribute.st_mode & S_IFREG) {
printf ("%s\n", fqname);
printf ("%s\n", fqname);
parse_plan_via_file(cfg_file);
is_valid += check_specific_tiff_file( fqname, flag_use_memorymapped_io);
are_valid += check_specific_tiff_file( fqname, flag_use_memorymapped_io);
clean_plan();
printf("\n");
@ -216,11 +206,11 @@ int main (int argc, char * argv[]) {
} else {
/* use tiff_file_or_dir */
parse_plan_via_file(cfg_file);
is_valid = check_specific_tiff_file( tiff_file_or_dir, flag_use_memorymapped_io);
are_valid = check_specific_tiff_file( tiff_file_or_dir, flag_use_memorymapped_io);
clean_plan();
}
} while (index_of_tiff_file_or_dir < argc );
if (0 == is_valid) {
if (0 == are_valid) {
exit(EXIT_SUCCESS);
} else {
exit(EXIT_FAILURE);


+ 10
- 18
src/checkit_tiff_risk.c View File

@ -1,7 +1,7 @@
/* rule based checks if given TIFF is a specific baseline TIFF
*
*
* author: Andreas Romeyke, 2015/16
* licensed under conditions of libtiff
* licensed under conditions of libtiff
* (see http://libtiff.maptools.org/misc.html)
*
*/
@ -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
@ -55,20 +51,14 @@ int main(int argc, char * argv[]) {
flag_print_stats = FLAGGED;
break;
case '?': /* something goes wrong */
/*
if (optopt == 'r') {
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
return (-1);
}
else*/ if (isprint (optopt)) {
if (isprint (optopt)) {
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
return (-1);
}
else if (0 !=optopt) {
} else if (0 !=optopt) {
fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
return (-1);
}
break;
}
break;
default:
abort();
}
@ -87,10 +77,12 @@ int main(int argc, char * argv[]) {
ret_t res=get_first_IFD(ctif, &offset);
if (res.returncode == is_valid) {
mem_map_t * memmap_p = scan_mem_map(ctif);
if (FLAGGED == flag_print_map)
if (FLAGGED == flag_print_map) {
print_mem_map ( memmap_p );
if (FLAGGED == flag_print_stats)
}
if (FLAGGED == flag_print_stats) {
print_mem_stats( memmap_p );
}
return (EXIT_SUCCESS);
} else {
return (EXIT_FAILURE);


+ 55
- 30
src/headers/check.h View File

@ -1,13 +1,16 @@
/* rule based checks if given TIFF is a specific baseline TIFF
*
*
* author: Andreas Romeyke, 2015-2017
* licensed under conditions of libtiff
* licensed under conditions of libtiff
* (see file LICENSE)
*
*/
#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,16 +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];
uint8 * streamp; /* TODO: address of memory-mapped tif stream */
char *filename; /* filename */
uint8 * streamp; /* address of memory-mapped tif stream */
uint8 * actual_streamp;
uint32 streamlen; /* TODO: length of tif stream/file (in bytes) */
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 */
char isbyteswapped; /* true if BigEndian */
char *filename; /* filename */
/* TODO: add file size */
bool_t isbyteswapped; /* true if BigEndian */
int tag_cache[MAXTAGS];
} ctiff_t;
typedef enum{
@ -62,10 +70,11 @@ typedef enum{
rm_summary_valid,
rm_summary_invalid,
} 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
@ -128,19 +137,16 @@ typedef enum {
tagerror_count_results_in_offsets_overflow, /* example: rational is defined as 2 uint32. offset is defined as uint32. If we read count>2147483647 we got offset overflow */
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,
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,20 +224,38 @@ 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);
ret_t tif_fails(const char* fail_message);
@ -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);
@ -263,13 +287,14 @@ ret_t check_datetime(ctiff_t * ctif);
ret_t check_icc(ctiff_t * ctif);
ret_t check_has_only_one_ifd(ctiff_t * ctif);
ret_t check_tagorder(ctiff_t * ctif);
ret_t check_tag_has_valid_asciivalue(ctiff_t * ctif, tag_t tag);
ret_t check_tag_has_valid_asciivalue(ctiff_t * ctif, tag_t tag);
ret_t check_tag_has_value_matching_regex(ctiff_t * ctif, tag_t tag, const char* regex_string);
ret_t check_all_offsets_are_word_aligned(ctiff_t * ctif);
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);


+ 10
- 9
src/headers/check_helper.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)
*
*/
@ -33,22 +33,23 @@ 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, 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);
ret_t parse_header_and_endianess(ctiff_t * ctif );
uint32 get_next_ifd_pos( ctiff_t * ctif, uint32 actual_pos );
uint16 get_ifd0_count( ctiff_t * ctif );
char is_byteswapped( ctiff_t * ctif );
int is_byteswapped( ctiff_t * ctif );
ret_t get_first_IFD(ctiff_t * ctif, uint32 * ifd);
ret_t set_value_found_ret (ret_t * rp, const char * msg);
returncode_t __add_to_render_pipeline_via_strncpy (retmsg_t ** pointer, const char * src, rm_type_t src_type);
void __clean_render_pipeline( retmsg_t * pointer );
#define STRING_AND_LEN(str) str, strlen( str )
returncode_t __add_to_render_pipeline_via_strncpy (retmsg_t ** pointer, const char * src, size_t src_len, rm_type_t src_type);
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

+ 5
- 6
src/headers/check_renderer.h View File

@ -1,7 +1,7 @@
/* rule based checks if given TIFF is a specific baseline TIFF
*
*
* author: Andreas Romeyke, 2015-2017
* licensed under conditions of libtiff
* licensed under conditions of libtiff
* (see http://libtiff.maptools.org/misc.html)
*
*/
@ -13,17 +13,16 @@
/* 65536 Tags a 256 chars message + 100 Messages */
/* #define RENDERSIZE (65536*256 + 100*256) */
#define RENDERSIZE (4096)
typedef enum{ render_default, render_ansi, render_xml} render_type;
#define RENDERMINSIZE (512)
#define RENDERMAXSIZE (33554432)
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_ */


+ 27
- 48
src/helper/check_helper.c View File

@ -6,82 +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
*/
char * secstrcat (char * dest, const char * src, size_t * maxsize_p) {
assert(NULL != maxsize_p);
size_t maxsize = *maxsize_p;
if (NULL == dest) {
fprintf(stderr, "internal error, dest is NULL!\n");
exit(EXIT_FAILURE);
}
if (NULL == src) {
} else {
int destsize = strnlen(dest, maxsize);
int srclen = strnlen(src, maxsize);
if (destsize+srclen < maxsize-1) {
strncat( dest, src, srclen);
} else {
int new_maxsize=(((destsize+srclen) / RENDERSIZE)+1) * RENDERSIZE-1;
if (new_maxsize < 4096*RENDERSIZE && new_maxsize > 0) {
char * dest_new = NULL;
dest_new = realloc(dest, (new_maxsize+1) * sizeof(char));
if (NULL == dest_new) {
perror( "Could not realloc memory");
exit( could_not_allocate_memory );
} else {
*maxsize_p = new_maxsize;
dest = dest_new;
strncat( dest, src, destsize +srclen);
}
}
/* dest should not exceed 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 array[VALUESTRLEN];
char* int2str(int v) {
char array[VALUESTRLEN];
snprintf(array, sizeof(array), "%i", v);
return strdup(array);
}
const char* frac2str(int d, int n) {
char<