Debian Codegraph @

src/lib/ifdrules/check_all_offsets_greater_zero.c

raw
1 /* 'checkit_tiff' is a conformance checker for baseline TIFFs
2 *
3 * author: Andreas Romeyke, 2015-2022
4 * licensed under conditions of libtiff
5 * (see http://libtiff.maptools.org/misc.html)
6 *
7 */
8
9 #include "check.h"
10 #include "check_helper.h"
11 #include "ctstring.h"
12
13 /* check if offsets are greater zero */
14 ret_t check_all_offsets_are_greater_zero(ctiff_t * ctif) {
15 GET_EMPTY_RET(ret);
16 TIFP_CHECK( ctif, ret);
17 uint16 count = get_ifd0_count( ctif);
18 for (int tagidx = 0; tagidx< count; tagidx++) {
19 ifd_entry_t ifd_entry = TIFFGetRawTagIFDListEntry( ctif, ctif->ifd0, tagidx );
20 uint32 tag = TIFFGetRawTagListEntry( ctif, ctif->ifd0, tagidx);
21 if (ifd_entry.value_or_offset==is_offset || tag == TIFFTAG_EXIFIFD) {
22 uint32 offset=0;
23 if (ifd_entry.value_or_offset==is_offset) offset = ifd_entry.data32offset;
24 else if (tag == TIFFTAG_EXIFIFD) {
25 if (ifd_entry.count > 1) {
26 string_t msg = uint2str(ifd_entry.count);
27 ret = set_value_found_ret_with_returncode(&ret, msg, tagerror_expected_count_isgreaterone);
28 return ret;
29 }
30 switch (ifd_entry.datatype) {
31 case TIFF_LONG: { /* correct type */
32 offset = ifd_entry.data32;
33 break;
34 }
35 default: { /* incorrect type for EXIF IFD */
36 ret = set_value_found_ret_with_returncode(&ret, str(TIFFTypeName(ifd_entry.datatype)),
37 tagerror_unexpected_type_found);
38 return ret;
39 /* break; */
40 };
41
42 }
43 } /* end else if tag == TIFFTAG_EXIFIFD */
44 if ( 0 == offset) {
45 // FIXME: tif_fails?
46 ret = set_value_found_ret_formatted_with_returncode( &ret, tagerror_offset_is_zero, "tag %u pointing to 0x%08x", tag, offset);
47 return ret;
48 }
49 }
50 }
51 ret.returncode=is_valid;
52 return ret;
53 }
54 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 smarttab expandtab :*/