Browse Source

- replaced get_empty_ret() by macro GET_EMPTY_RET(), because faster code

- added new returncode_t entry "tagerror_count_results_in_offsets_overflow"
- changed signature of check_tag_has_some_of_these_values() using const
- changed signature of check_tag_has_valuelist() using const
- minor fixes
- fixed warnings for int-types and signed-unsigned conversion
- fixed missed initializations
-
pull/6/head
Andreas Romeyke 5 years ago
parent
commit
de8206f9ce
  1. 18
      src/checkit_tiff.c
  2. 5
      src/headers/check.h
  3. 20
      src/headers/check_helper.h
  4. 4
      src/headers/config_parser.h
  5. 7
      src/helper/check_helper.c
  6. 76
      src/helper/check_tiffparse.c
  7. 2
      src/ifdrules/check_all_IFDs_are_word_aligned.c
  8. 2
      src/ifdrules/check_all_offsets_are_used_once_only.c
  9. 2
      src/ifdrules/check_all_offsets_are_word_aligned.c
  10. 2
      src/ifdrules/check_has_only_one_ifd.c
  11. 2
      src/ifdrules/check_tagorder.c
  12. 5
      src/messages/msg_parser.c
  13. 12
      src/parser/config_parser.c
  14. 12
      src/risk_analyzer/lst_offset_mappings.c
  15. 6
      src/tagrules/check_datetime.c
  16. 2
      src/tagrules/check_icc.c
  17. 2
      src/tagrules/check_notag.c
  18. 28
      src/tagrules/check_tag_has_some_of_these_values.c
  19. 6
      src/tagrules/check_tag_has_valid_asciivalue.c
  20. 2
      src/tagrules/check_tag_has_valid_type.c
  21. 10
      src/tagrules/check_tag_has_value_in_range.c
  22. 6
      src/tagrules/check_tag_has_value_matching_regex.c
  23. 2
      src/tagrules/check_tag_has_value_quiet.c
  24. 6
      src/tagrules/check_tag_has_valuelist.c
  25. 2
      src/tagrules/check_tag_quiet.c

18
src/checkit_tiff.c

@ -50,13 +50,9 @@ void help () {
int check_specific_tiff_file( const char * tiff_file, int use_memmapped) {
ret_t res = get_empty_ret();
GET_EMPTY_RET(res)
/* init render pipeline */
retmsg_t * render_pipeline = malloc( sizeof( retmsg_t) );
const char * render_result_string = NULL;
if (NULL == render_pipeline) {
exit (could_not_allocate_memory);
}
retmsg_t * actual_render = render_pipeline;
actual_render->rm_type = rm_file;
actual_render->rm_msg = malloc ( sizeof(char) * VALUESTRLEN );
@ -85,12 +81,14 @@ int check_specific_tiff_file( const char * tiff_file, int use_memmapped) {
execute_plan(ctif);
res = print_plan_results( actual_render);
renderer_exit:
render_result_string = renderer( render_pipeline );
printf("%s\n", render_result_string);
{
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 );
free((void *) render_result_string);
}
free_ctif( ctif );
/* free all entries of render pipeline */
__clean_render_pipeline( render_pipeline );
free(render_result_string);
if (NULL != res.value_found) {
free(res.value_found);
res.value_found = NULL;

5
src/headers/check.h

@ -95,6 +95,7 @@ typedef enum {
parser_error_wrong_function_found_in_parser_state_exe_stack,
parser_logicalor_error,
tagerror_expected_offsetdata,
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 */
} returncode_t;
@ -216,8 +217,8 @@ const char* frac2str(int d, int n);
const 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, unsigned int * values);
ret_t check_tag_has_valuelist( ctiff_t * ctif, tag_t tag, int count, unsigned int * values);
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_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);

20
src/headers/check_helper.h

@ -28,11 +28,11 @@ TIFFDataType TIFFGetRawTagType(ctiff_t * ctif, tag_t tag);
ifd_entry_t TIFFGetRawIFDEntry( ctiff_t * ctif, tag_t tag);
ifd_entry_t TIFFGetRawTagIFDListEntry( ctiff_t * ctif, int tagidx );
int TIFFGetRawTagListIndex(ctiff_t * ctif, tag_t tag);
ret_t TIFFGetFieldASCII(ctiff_t * ctif, tag_t tag, char** string_p, int * countp);
ret_t TIFFGetFieldLONG(ctiff_t * ctif, tag_t tag, uint32 ** long_p, int * countp);
ret_t TIFFGetFieldSHORT(ctiff_t * ctif, tag_t tag, uint16 ** short_p, int * countp);
ret_t TIFFGetFieldRATIONAL(ctiff_t * ctif, tag_t tag, float ** float_p, int * countp);
ret_t read_offsetdata( ctiff_t * ctif, uint32 address, uint32 count, uint16 datatype, offset_t * offsetp);
ret_t TIFFGetFieldASCII(ctiff_t * ctif, const tag_t tag, char** result_string_p, uint32 * result_countp);
ret_t TIFFGetFieldLONG(ctiff_t * ctif, const tag_t tag, uint32 ** result_long_p, uint32 * result_countp);
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);
char * secstrcat (char * dest, const char * src, int maxsize);
ctiff_t * initialize_ctif( const char * tiff_file, ct_ioflag_t );
void free_ctif( ctiff_t * ctif);
@ -42,8 +42,16 @@ uint32 get_next_ifd_pos( ctiff_t * ctif, uint32 actual_pos );
uint16 get_ifd0_count( ctiff_t * ctif );
char is_byteswapped( ctiff_t * ctif );
ret_t get_first_IFD(ctiff_t * ctif, uint32 * ifd);
ret_t get_empty_ret();
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 GET_EMPTY_RET(ret) \
ret_t ret; \
ret.value_found = NULL; \
ret.logical_or_count = 0; \
ret.returncode = should_not_occure; \
\
#endif

4
src/headers/config_parser.h

@ -75,8 +75,8 @@ typedef struct full_res_s {
int lineno;
tag_t tag;
function_t function;
const char * expected_value;
const char * found_value;
char * expected_value;
char * found_value;
int logical_or_count;
returncode_t returncode;

7
src/helper/check_helper.c

@ -90,13 +90,6 @@ long long fsize(int fd) {
return st.st_size;
}
ret_t get_empty_ret () {
ret_t ret;
ret.value_found = NULL;
ret.logical_or_count = 0;
ret.returncode = should_not_occure;
return ret;
}
ret_t set_value_found_ret (ret_t * rp, const char * msg) {
assert( NULL != rp);

76
src/helper/check_tiffparse.c

@ -160,12 +160,12 @@ 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) {
ret_t ret= get_empty_ret();
GET_EMPTY_RET(ret)
tifp_check( ctif);
float * valp = NULL;
float val;
int found;
uint32 found;
ret =TIFFGetFieldRATIONAL(ctif, tag, &valp, &found);
if (1 == found) {
val = * valp;
@ -182,12 +182,12 @@ 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) {
ret_t ret= get_empty_ret();
GET_EMPTY_RET(ret)
tifp_check( ctif);
uint16 * valp = NULL;
uint16 val;
int found;
uint32 found;
ret=TIFFGetFieldSHORT(ctif, tag, &valp, &found);
if (1 == found) {
val = *valp;
@ -207,13 +207,13 @@ 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) {
ret_t ret= get_empty_ret();
GET_EMPTY_RET(ret)
tifp_check( ctif);
uint32 * valp = NULL;
uint32 val;
int found;
uint32 found;
ret=TIFFGetFieldLONG(ctif, tag, &valp, &found);
if (1 == found) {
val = *valp;
@ -231,7 +231,7 @@ ret_t check_tag_has_u32value(ctiff_t * ctif, tag_t tag, uint32 value) {
ret_t parse_header_and_endianess(ctiff_t * ctif) {
ret_t ret= get_empty_ret();
GET_EMPTY_RET(ret)
/* seek the image file directory (bytes 4-7) */
//ct_seek(fd, (off_t) 0, SEEK_SET);
@ -289,7 +289,7 @@ ret_t parse_header_and_endianess(ctiff_t * ctif) {
}
ret_t get_first_IFD(ctiff_t * ctif, uint32 * ifd) {
ret_t ret= get_empty_ret();
GET_EMPTY_RET(ret)
int isByteSwapped = ctif->isbyteswapped;
/* seek the image file directory (bytes 4-7) */
if (ct_seek(ctif, 4, SEEK_SET) != 4 ) {
@ -439,11 +439,11 @@ void offset_swablong(ctiff_t * ctif, uint32 * address, uint16 count) {
}
}
/* get count-data datastream from offset-address */
ret_t read_offsetdata( ctiff_t * ctif, uint32 address, uint32 count, uint16 datatype, offset_t * offset_p) {
ret_t read_offsetdata(ctiff_t * ctif, const uint32 address, const uint32 count, const uint16 datatype, offset_t * offset_p) {
assert(NULL != offset_p);
offset_p->count = count;
offset_p->datatype = datatype;
ret_t ret = get_empty_ret();
GET_EMPTY_RET(ret)
ret.returncode = is_valid;
/* ct_read and seek to IFD address */
if (ct_seek(ctif, address, SEEK_SET) != address) {
@ -838,10 +838,10 @@ uint32 get_next_ifd_pos(ctiff_t * ctif, uint32 actual_pos) {
return offset;
}
ret_t TIFFGetFieldASCII(ctiff_t * ctif, tag_t tag, char** string_pp, int * countp ) {
ret_t TIFFGetFieldASCII(ctiff_t * ctif, const tag_t tag, char** string_pp, uint32 * countp ) {
assert( *string_pp == NULL);
assert( countp != NULL);
ret_t ret = get_empty_ret();
GET_EMPTY_RET(ret)
int tagidx = TIFFGetRawTagListIndex(ctif, tag);
if (tagidx >= 0) { /* there exists the tag */
ifd_entry_t entry = TIFFGetRawTagIFDListEntry( ctif, tagidx );
@ -855,7 +855,7 @@ ret_t TIFFGetFieldASCII(ctiff_t * ctif, tag_t tag, char** string_pp, int * count
memset(*string_pp, '\0', entry.count+1);
if (entry.value_or_offset == is_value) {
assert (entry.count >= 0 && entry.count <= 4);
for (int i=0; i<entry.count; i++) {
for (uint32 i=0; i<entry.count; i++) {
(*string_pp)[i]=entry.data8[i];
}
ret.returncode=is_valid;
@ -872,7 +872,7 @@ ret_t TIFFGetFieldASCII(ctiff_t * ctif, tag_t tag, char** string_pp, int * count
char * s = *(string_pp);
/* DEBUG: */
//printf("tag=%i entry.count=%i offset.count=%i\n", tag, entry.count, offset.count);
for (int i=0; i<entry.count; i++) {
for (uint32 i=0; i<entry.count; i++) {
//printf("P[%i]=%c\n", i, *p);
*(s++) = *(p++);
}
@ -886,14 +886,23 @@ ret_t TIFFGetFieldASCII(ctiff_t * ctif, tag_t tag, char** string_pp, int * count
return ret;
}
ret_t TIFFGetFieldLONG(ctiff_t * ctif, tag_t tag, uint32 ** long_pp, int * countp) {
ret_t TIFFGetFieldLONG(ctiff_t * ctif, const tag_t tag, uint32 ** long_pp, uint32 * countp) {
assert( *long_pp == NULL);
assert( countp != NULL);
*countp = -1; /* init */
ret_t ret = get_empty_ret();
GET_EMPTY_RET(ret)
int tagidx = TIFFGetRawTagListIndex(ctif, tag);
if (tagidx >= 0) { /* there exists the tag */
ifd_entry_t entry = TIFFGetRawTagIFDListEntry( ctif, tagidx );
uint32 overflow = (0xffffffff / (sizeof(uint32)));
if (entry.count > overflow) {
char msg[200];
snprintf(msg, 200, "count=%u overflow boundary=%u", entry.count, overflow);
ret = set_value_found_ret(&ret, msg);
ret.returncode = tagerror_count_results_in_offsets_overflow;
return ret;
}
*countp = entry.count;
*(long_pp) = malloc( sizeof(uint32) * entry.count);
if (NULL == (*long_pp)) {
@ -926,14 +935,23 @@ ret_t TIFFGetFieldLONG(ctiff_t * ctif, tag_t tag, uint32 ** long_pp, int * count
return ret;
}
ret_t TIFFGetFieldSHORT(ctiff_t * ctif, tag_t tag, uint16 ** short_pp, int * countp) {
ret_t TIFFGetFieldSHORT(ctiff_t * ctif, const tag_t tag, uint16 ** short_pp, uint32 * countp) {
assert( *short_pp == NULL);
assert( countp != NULL);
*countp = -1; /* init */
ret_t ret = get_empty_ret();
GET_EMPTY_RET(ret)
int tagidx = TIFFGetRawTagListIndex(ctif, tag);
if (tagidx >= 0) { /* there exists the tag */
ifd_entry_t entry = TIFFGetRawTagIFDListEntry( ctif, tagidx );
uint32 overflow = (0xffffffff / (sizeof(uint16)));
if (entry.count > overflow) {
char msg[200];
snprintf(msg, 200, "count=%u overflow boundary=%u", entry.count, overflow);
ret = set_value_found_ret(&ret, msg);
ret.returncode = tagerror_count_results_in_offsets_overflow;
return ret;
}
*countp = entry.count;
*(short_pp) = malloc( sizeof(uint16) * entry.count);
if (NULL == *(short_pp)) {
@ -967,14 +985,22 @@ ret_t TIFFGetFieldSHORT(ctiff_t * ctif, tag_t tag, uint16 ** short_pp, int * cou
return ret;
}
ret_t TIFFGetFieldRATIONAL(ctiff_t * ctif, tag_t tag, float ** float_pp, int * countp) {
ret_t TIFFGetFieldRATIONAL(ctiff_t * ctif, const tag_t tag, float ** float_pp, uint32 * countp) {
assert( *float_pp == NULL);
assert( countp != NULL);
*countp = -1; /* init */
ret_t ret = get_empty_ret();
*countp = 0; /* init */
GET_EMPTY_RET(ret)
int tagidx = TIFFGetRawTagListIndex(ctif, tag);
if (tagidx >= 0) { /* there exists the tag */
ifd_entry_t entry = TIFFGetRawTagIFDListEntry( ctif, tagidx );
uint32 overflow = (0xffffffff / (2*sizeof(uint32)));
if (entry.count > overflow) {
char msg[200];
snprintf(msg, 200, "count=%u overflow boundary=%u", entry.count, overflow);
ret = set_value_found_ret(&ret, msg);
ret.returncode = tagerror_count_results_in_offsets_overflow;
return ret;
}
//printf("entry.count=%i\n", entry.count);
*countp = entry.count;
*(float_pp) = malloc( sizeof(float) * (entry.count));
@ -1000,10 +1026,10 @@ ret_t TIFFGetFieldRATIONAL(ctiff_t * ctif, tag_t tag, float ** float_pp, int * c
uint32 numerator = 0;
uint32 denominator = 0;
uint32 * orig_data32p = offset.data32p;
for (int i = 0; i< entry.count; i++) {
numerator = *(orig_data32p++);
denominator = *(orig_data32p++);
//printf("DEBUG: numerator=%i denumeator=%i\n", numerator, denominator);
for (uint32 i = 0; i< entry.count; i++, orig_data32p+=2) {
numerator = *(orig_data32p);
denominator = *(orig_data32p+1);
//printf("DEBUG: numerator=%u denumeator=%u\n", numerator, denominator);
float v;
if (denominator == 0) {
v=NAN;

2
src/ifdrules/check_all_IFDs_are_word_aligned.c

@ -14,7 +14,7 @@
/* check if IFDs are word aligned */
ret_t check_all_IFDs_are_word_aligned(ctiff_t * ctif) {
ret_t ret = get_empty_ret();
GET_EMPTY_RET(ret)
tifp_check( ctif);
uint32 ifd = get_ifd0_pos( ctif ); /* TODO: check all other IFDs, too */

2
src/ifdrules/check_all_offsets_are_used_once_only.c

@ -13,7 +13,7 @@
/* check if offsets are used only once */
ret_t check_all_offsets_are_used_once_only(ctiff_t * ctif) {
ret_t ret = get_empty_ret();
GET_EMPTY_RET(ret)
tifp_check( ctif);
int count = get_ifd0_count( ctif);
int tagidx;

2
src/ifdrules/check_all_offsets_are_word_aligned.c

@ -13,7 +13,7 @@
/* check if offsets are word aligned */
ret_t check_all_offsets_are_word_aligned(ctiff_t * ctif) {
ret_t ret = get_empty_ret();
GET_EMPTY_RET(ret)
tifp_check( ctif);
int count = get_ifd0_count( ctif);
int tagidx;

2
src/ifdrules/check_has_only_one_ifd.c

@ -12,7 +12,7 @@
/* check if only one IFD exists */
ret_t check_has_only_one_ifd(ctiff_t * ctif) {
ret_t ret = get_empty_ret();
GET_EMPTY_RET(ret)
tifp_check( ctif);
/* next commented lines, because TIFFNumberOfDirectories are in endless loop,
* if the TIFF file from https://github.com/EasyinnovaSL/DPFManager/blob/develop/src/test/resources/IFD%20struct/Circular%20E.tif

2
src/ifdrules/check_tagorder.c

@ -12,7 +12,7 @@
#include <errno.h>
ret_t check_tagorder(ctiff_t * ctif) {
ret_t ret = get_empty_ret();
GET_EMPTY_RET(ret)
tifp_check( ctif);
if (has_sorted_tags != ctif->tagorder) {
uint32 offset = get_ifd0_pos(ctif);

5
src/messages/msg_parser.c

@ -32,7 +32,7 @@ const char * get_parser_function_description( function_t f ) {
case fc_internal_logic_combine: return "One or more conditions in a logical_or operation were false."; break;
case fc_dummy: return "Dummy."; break;
}
return "should not occur";
return "missed function description, should not occur";
}
const char * get_parser_error_description( returncode_t r ) {
@ -85,9 +85,10 @@ const char * get_parser_error_description( returncode_t r ) {
case parser_error_wrong_function_found_in_parser_state_exe_stack: return "internal error: current stack function name not part of predefined name enumeration."; break;
case parser_logicalor_error: return "internal error: parser error in logical_or rule"; break;
case tagerror_expected_offsetdata: return "Expected offset data but found actual values encoded in tag."; break;
case tagerror_count_results_in_offsets_overflow: return "Tag counts n elements, but resulting offset exceeds 4GB size"; break;
}
return "should not occur";
return "missed error description, should not occur";
}
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 smarttab expandtab :*/

12
src/parser/config_parser.c

@ -329,7 +329,7 @@ void execute_plan (ctiff_t * ctif) {
exe_printstack();
#endif
do {
ret_t ret= get_empty_ret();
GET_EMPTY_RET(ret)
char * expected_value=NULL;
internal_entry_t exe = exe_pop();
@ -403,19 +403,19 @@ void execute_plan (ctiff_t * ctif) {
case fc_tag_has_value_in_range: { int a = exe_i_pop(&exe);
int b = exe_i_pop(&exe);
expected_value = __ch_malloc(expected_value);
snprintf(expected_value, VALUESTRLEN, "%li -- %li", a, b);
snprintf(expected_value, VALUESTRLEN, "%i -- %i", a, b);
ret = check_tag_has_value_in_range(ctif, exe.tag, a, b);
break;
}
case fc_tag_has_value: { int a = exe_i_pop(&exe);
expected_value = __ch_malloc(expected_value);
snprintf(expected_value, VALUESTRLEN, "%li", a);
snprintf(expected_value, VALUESTRLEN, "%i", a);
ret = check_tag_has_value(ctif, exe.tag, a);
break;
}
case fc_tag_has_value_quiet: { int a = exe_i_pop(&exe);
expected_value = __ch_malloc(expected_value);
snprintf(expected_value, VALUESTRLEN, "%li", a);
snprintf(expected_value, VALUESTRLEN, "%i", a);
ret = check_tag_has_value_quiet(ctif, exe.tag, a);
break;
}
@ -444,7 +444,7 @@ void execute_plan (ctiff_t * ctif) {
case fc_all_IFDs_are_word_aligned: { ret = check_all_IFDs_are_word_aligned(ctif); break;}
case fc_internal_logic_combine: { break; }
default: {
ret_t res = get_empty_ret();
GET_EMPTY_RET(res)
res.value_found = __ch_malloc(res.value_found);
fprintf(stderr, "lineno=%i, stack entry tag %i", parser_state.lineno, exe.tag);
#ifdef EXE_DEBUG
@ -1159,7 +1159,7 @@ void clean_plan_results() {
/* prints a plan (list) of functions and their results*/
ret_t print_plan_results(retmsg_t * actual_render) {
ret_t res = get_empty_ret();
GET_EMPTY_RET(res)
#ifdef DEBUG
printf("print plan results:\n");
printf("####################(\n");

12
src/risk_analyzer/lst_offset_mappings.c

@ -130,7 +130,7 @@ mem_map_t * scan_mem_map(ctiff_t * ctif) {
case TIFF_LONG: {
/* value */
if (stripoffset_entry.value_or_offset == is_value) {
for (int i=0; i< stripoffset_entry.count; i++) {
for (uint32 i=0; i< stripoffset_entry.count; i++) {
stripoffset_values[i] = stripoffset_entry.data32;
}
}
@ -139,7 +139,7 @@ mem_map_t * scan_mem_map(ctiff_t * ctif) {
offset_t offset;
ret_t ret = read_offsetdata(ctif, stripoffset_entry.data32offset, stripoffset_entry.count, stripoffset_entry.datatype, &offset);
uint32 * p = offset.data32p;
for (int i=0; i< stripoffset_entry.count; i++) {
for (uint32 i=0; i< stripoffset_entry.count; i++) {
uint32 pval = *p;
if (is_byteswapped(ctif)) {
TIFFSwabLong(&pval);
@ -153,7 +153,7 @@ mem_map_t * scan_mem_map(ctiff_t * ctif) {
case TIFF_SHORT: {
/* value */
if (stripoffset_entry.value_or_offset == is_value) {
for (int i=0; i< stripoffset_entry.count; i++) {
for (uint32 i=0; i< stripoffset_entry.count; i++) {
stripoffset_values[i]= stripoffset_entry.data16[i];
}
}
@ -162,7 +162,7 @@ mem_map_t * scan_mem_map(ctiff_t * ctif) {
offset_t offset;
ret_t ret = read_offsetdata(ctif, stripoffset_entry.data32offset, stripoffset_entry.count, stripoffset_entry.datatype, &offset);
uint16 * p = offset.data16p;
for (int i=0; i< count; i++) {
for (uint32 i=0; i< count; i++) {
uint16 pval = *p;
if (is_byteswapped(ctif)) {
TIFFSwabShort(&pval);
@ -195,8 +195,8 @@ mem_map_t * scan_mem_map(ctiff_t * ctif) {
*/
/* add all unused areas */
int memmap_orig_count = memmap.count;
for (int j=1; j< memmap_orig_count; j++) {
uint32 memmap_orig_count = memmap.count;
for (uint32 j=1; j< memmap_orig_count; j++) {
mem_map_entry_t * prev=memmap.base_p+j-1;
mem_map_entry_t * act =memmap.base_p+j;
uint32 estimated_offset = (prev->offset + prev->count);

6
src/tagrules/check_datetime.c

@ -50,7 +50,7 @@ int test_plausibility (int * year, int * month, int * day, int * hour, int * min
*/
ret_t check_datetime(ctiff_t * ctif ) {
ret_t ret = get_empty_ret();
GET_EMPTY_RET(ret)
tifp_check( ctif);
ret_t rc=check_tag_quiet(ctif, TIFFTAG_DATETIME);
@ -65,7 +65,7 @@ ret_t check_datetime(ctiff_t * ctif ) {
ret.returncode = tagerror_unexpected_type_found;
return ret;
}
int count=0;
uint32 count=0;
char *datetime=NULL;
ret = TIFFGetFieldASCII(ctif, TIFFTAG_DATETIME, &datetime, &count);
if (ret.returncode != is_valid) return ret;
@ -78,7 +78,7 @@ ret_t check_datetime(ctiff_t * ctif ) {
int min=0;
int sec=0;
int r = 0;
for (int i=0; i<count; i++) {
for (uint32 i=0; i<count; i++) {
if ((datetime[i] == '\0') && (i != 19)) { /* \0 at 20th byte allowed */
r = i+1;
break;

2
src/tagrules/check_icc.c

@ -13,7 +13,7 @@
/** checks a ICC tag, see Annex B of http://www.color.org/specification/ICC1v43_2010-12.pdf
*/
ret_t check_icc(ctiff_t * ctif ) {
ret_t ret = get_empty_ret();
GET_EMPTY_RET(ret)
tifp_check( ctif);
ifd_entry_t ifd_entry = TIFFGetRawIFDEntry(ctif, TIFFTAG_ICCPROFILE);

2
src/tagrules/check_notag.c

@ -13,7 +13,7 @@
/* checks if TIF does not have a specified tag,
* needed only for checks to ensure whitelist */
ret_t check_notag(ctiff_t * ctif, tag_t tag) {
ret_t ret = get_empty_ret();
GET_EMPTY_RET(ret)
tifp_check( ctif);
ret_t r = check_tag_quiet( ctif, tag);
if (is_valid == r.returncode) {

28
src/tagrules/check_tag_has_some_of_these_values.c

@ -13,12 +13,12 @@
#define DEBUG
*/
ret_t check_tag_has_some_of_these_values(ctiff_t * ctif, tag_t tag, int count, unsigned int * values) {
ret_t ret= get_empty_ret();
ret_t check_tag_has_some_of_these_values(ctiff_t * ctif, tag_t tag, int count, const unsigned int * values) {
GET_EMPTY_RET(ret)
tifp_check( ctif);
ret=check_tag_quiet(ctif, tag);
if (ret.returncode != is_valid) return ret;
unsigned int * p = values;
const unsigned int * p = values;
TIFFDataType datatype = TIFFGetRawTagType( ctif, tag );
switch (datatype) {
@ -34,10 +34,10 @@ ret_t check_tag_has_some_of_these_values(ctiff_t * ctif, tag_t tag, int count, u
p++;
}
uint32 * valp = NULL;
uint32 val;
int count;
ret = TIFFGetFieldLONG(ctif, tag, &valp, &count);
if (count >0) {
uint32 val=0;
uint32 vcount=0;
ret = TIFFGetFieldLONG(ctif, tag, &valp, &vcount);
if (vcount >0) {
val = *valp;
char value[VALUESTRLEN];
snprintf(value, sizeof(value), "%u", val);
@ -59,10 +59,10 @@ ret_t check_tag_has_some_of_these_values(ctiff_t * ctif, tag_t tag, int count, u
p++;
}
uint16 * valp = NULL;
uint16 val;
int count;
ret = TIFFGetFieldSHORT(ctif, tag, &valp, &count);
if (count >0) {
uint16 val=0;
uint32 vcount=0;
ret = TIFFGetFieldSHORT(ctif, tag, &valp, &vcount);
if (vcount >0) {
val = *valp;
char value[VALUESTRLEN];
snprintf(value, sizeof(value), "%u", val);
@ -84,9 +84,9 @@ ret_t check_tag_has_some_of_these_values(ctiff_t * ctif, tag_t tag, int count, u
p++;
}
float * valp = NULL;
float val;
int count;
ret = TIFFGetFieldRATIONAL(ctif, tag, &valp, &count);
float val=0.0f;
uint32 vcount=0;
ret = TIFFGetFieldRATIONAL(ctif, tag, &valp, &vcount);
if (count >0) {
val = * valp;
char value[VALUESTRLEN];

6
src/tagrules/check_tag_has_valid_asciivalue.c

@ -14,7 +14,7 @@
/* checks if TIF with tag and type ASCII */
ret_t check_tag_has_valid_asciivalue(ctiff_t * ctif, tag_t tag) {
ret_t ret = get_empty_ret();
GET_EMPTY_RET(ret)
tifp_check( ctif);
ret=check_tag_quiet(ctif, tag);
if (ret.returncode != is_valid) return ret;
@ -28,10 +28,10 @@ ret_t check_tag_has_valid_asciivalue(ctiff_t * ctif, tag_t tag) {
int r = 0;
char * val=NULL;
if (datatype == TIFF_ASCII) {
int count;
uint32 count=0;
ret = TIFFGetFieldASCII(ctif, tag, &val, &count);
if (0 < count) { /* there exists a tag */
for (int i=0; i<count; i++) {
for (uint32 i=0; i<count; i++) {
if (string[i] == '\0') {
r = i+1;
break;

2
src/tagrules/check_tag_has_valid_type.c

@ -12,7 +12,7 @@
/* checks if TIF has a specified tag */
ret_t check_tag_has_valid_type(ctiff_t * ctif, tag_t tag) {
ret_t ret = get_empty_ret();
GET_EMPTY_RET(ret)
tifp_check( ctif);
ret=check_tag_quiet(ctif, tag);

10
src/tagrules/check_tag_has_value_in_range.c

@ -16,7 +16,7 @@
*/
ret_t check_tag_has_value_in_range(ctiff_t * ctif, tag_t tag, unsigned int a, unsigned int b) {
ret_t ret = get_empty_ret();
GET_EMPTY_RET(ret)
tifp_check( ctif);
ret=check_tag_quiet(ctif, tag);
@ -26,8 +26,8 @@ ret_t check_tag_has_value_in_range(ctiff_t * ctif, tag_t tag, unsigned int a, un
switch (datatype) {
case TIFF_LONG: {
uint32 * valp = NULL;
uint32 val;
int found;
uint32 val=0;
uint32 found=0;
ret=TIFFGetFieldLONG(ctif, tag, &valp, &found);
if (ret.returncode != is_valid) return ret;
if (1 == found) {
@ -61,7 +61,7 @@ ret_t check_tag_has_value_in_range(ctiff_t * ctif, tag_t tag, unsigned int a, un
case TIFF_SHORT: {
uint16 * valp = NULL;
uint16 val;
int found;
uint32 found=0;
ret =TIFFGetFieldSHORT(ctif, tag, &valp, &found);
if (ret.returncode != is_valid) return ret;
if (1 == found) {
@ -95,7 +95,7 @@ ret_t check_tag_has_value_in_range(ctiff_t * ctif, tag_t tag, unsigned int a, un
case TIFF_RATIONAL: {
float * valp = NULL;
float val;
int found;
uint32 found=0;
ret=TIFFGetFieldRATIONAL(ctif, tag, &valp, &found);
if (ret.returncode != is_valid) return ret;
if (1 == found) {

6
src/tagrules/check_tag_has_value_matching_regex.c

@ -9,7 +9,7 @@
ret_t check_tag_has_value_matching_regex(ctiff_t * ctif, tag_t tag, const char * regex_string) {
ret_t ret=get_empty_ret();
GET_EMPTY_RET(ret)
tifp_check( ctif);
ret=check_tag_quiet(ctif, tag);
if (ret.returncode != is_valid) return ret;
@ -18,7 +18,7 @@ ret_t check_tag_has_value_matching_regex(ctiff_t * ctif, tag_t tag, const char *
switch (datatype) {
case TIFF_ASCII: {
char * val=NULL;
int count;
uint32 count=0;
ret = TIFFGetFieldASCII(ctif, tag, &val, &count);
if (ret.returncode != is_valid) return ret;
if (0 < count) {
@ -38,7 +38,7 @@ ret_t check_tag_has_value_matching_regex(ctiff_t * ctif, tag_t tag, const char *
/* PCRE_NOTEMPTY: An empty string is not a valid match */
int rc = pcre_exec( re, NULL, val, count-1, 0,PCRE_NOTEMPTY, ovector, OVECCOUNT);
#ifdef DEBUG
printf("tag %s with count=%d and value='%s' -> rc=%d\n", TIFFTagName(tag), count, val, rc);
printf("tag %s with count=%u and value='%s' -> rc=%d\n", TIFFTagName(tag), count, val, rc);
#endif
pcre_free( re );
if (rc >= 0 ) {

2
src/tagrules/check_tag_has_value_quiet.c

@ -17,7 +17,7 @@
ret_t check_tag_has_value_quiet(ctiff_t * ctif, tag_t tag, unsigned int expected_value) {
ret_t ret = get_empty_ret();
GET_EMPTY_RET(ret)
tifp_check( ctif);
ret=check_tag_quiet(ctif, tag);
if (ret.returncode != is_valid) return ret;

6
src/tagrules/check_tag_has_valuelist.c

@ -15,8 +15,8 @@
#define DEBUG
*/
ret_t check_tag_has_valuelist(ctiff_t * ctif, tag_t tag, int count, unsigned int * values) {
ret_t ret = get_empty_ret();
ret_t check_tag_has_valuelist(ctiff_t * ctif, tag_t tag, int count, const unsigned int * values) {
GET_EMPTY_RET(ret)
tifp_check( ctif);
ret=check_tag_quiet(ctif, tag);
@ -39,7 +39,7 @@ ret_t check_tag_has_valuelist(ctiff_t * ctif, tag_t tag, int count, unsigned int
char value[VALUESTRLEN];
memset(value, '\0', VALUESTRLEN);
ifd_entry_t ifd_entry = TIFFGetRawIFDEntry(ctif, tag);
if (count != ifd_entry.count) {
if ((uint32) count != ifd_entry.count) {
snprintf(value, sizeof(value), "has %u values", ifd_entry.count);
ret = set_value_found_ret (&ret, value);
ret.returncode = tagerror_expected_count_differs;

2
src/tagrules/check_tag_quiet.c

@ -13,7 +13,7 @@
/* checks if TIF has a specified tag */
ret_t check_tag_quiet(ctiff_t * ctif, tag_t tag) {
ret_t ret = get_empty_ret();
GET_EMPTY_RET(ret)
tifp_check( ctif);
if (-1 < TIFFGetRawTagListIndex(ctif, tag)) {

Loading…
Cancel
Save