Browse Source

- (re-)added extended check for ascii-values

pull/10/head v0.4.2
Andreas Romeyke 3 years ago
parent
commit
2df702d334
  1. 1
      src/headers/check.h
  2. 3
      src/messages/msg_parser.c
  3. 22
      src/tagrules/check_tag_has_value_matching_regex.c

1
src/headers/check.h

@ -92,6 +92,7 @@ typedef enum {
tagerror_pcre_nomatch, /* regex does not match value */
pcre_compile_error, /* regex is wrong */
tagerror_multiple_zeros_in_asciivalue, /* doubled \0 in string */
tagerror_no_zero_as_end_of_string_in_asciivalue,
tagerror_denominator_is_zero_in_fract,
ifderror_offset_used_twice,
ifderror_multiple_ifd_detected,

3
src/messages/msg_parser.c

@ -90,7 +90,8 @@ const char * get_parser_error_description( returncode_t r ) {
case tagerror_encoded_as_value_excited_space: return "Tag value encoded as value but exceeded available space."; break; /* tag encoded as value instead as offset, but there is no enough space to hold it, pE. ICC-Profile encoded without offset */
case tagerror_pcre_nomatch: return "but doesn't."; break; /* regex does not match value */
case pcre_compile_error: return "The predefined Regex is invalid."; break; /* regex is wrong */
case tagerror_multiple_zeros_in_asciivalue: return "Multiple NULL-Bytes (\0) found in ASCII value."; break; /* doubled \0 in string */
case tagerror_multiple_zeros_in_asciivalue: return "Multiple NULL-Bytes (\\0) found in ASCII value."; break; /* doubled \0 in string */
case tagerror_no_zero_as_end_of_string_in_asciivalue: return "Missed NULL-Byte (\\0) at end of ASCII value."; break;
case tagerror_denominator_is_zero_in_fract: return "Denominator in fraction tag value is zero."; break;
case ifderror_offset_used_twice: return "but this offset was used twice."; break;
case ifderror_multiple_ifd_detected: return "but multiple IFDs were found."; break;

22
src/tagrules/check_tag_has_value_matching_regex.c

@ -19,9 +19,31 @@ ret_t check_tag_has_value_matching_regex(ctiff_t * ctif, tag_t tag, const char *
case TIFF_ASCII: {
char * val=NULL;
uint32 count=0;
int r = 0;
ret = TIFFGetFieldASCII(ctif, tag, &val, &count);
if (ret.returncode != is_valid) return ret;
if (0 < count) {
for (uint32 i=0; i<count-1; i++) {
if (val[i] == '\0' && val[i+1] =='\0') {
r = i+1;
break;
}
}
if (val[count-1] != '\0') {
char array[VALUESTRLEN];
snprintf(array, sizeof(array), "'%c' (at position %lu: '%s')", val[count-1], count-1, val);
ret = set_value_found_ret(&ret, array);
ret.returncode = tagerror_no_zero_as_end_of_string_in_asciivalue;
return ret;
}
if (r != 0) {
char array[VALUESTRLEN];
snprintf(array, sizeof(array), "'%s' (\\0 at position %i in %u-len)", val, r, count);
ret = set_value_found_ret(&ret, array);
ret.returncode = tagerror_multiple_zeros_in_asciivalue;
return ret;
}
#define OVECCOUNT 30 /* should be a multiple of 3 */
pcre *re;
int erroffset;

Loading…
Cancel
Save