Debian Codegraph @

src/lib/ifdrules/check_all_IFDs_are_word_aligned.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 static ret_t check_specific_ifd_word_aligned(uint32 ifd_pos, tag_t tag) {
14 GET_EMPTY_RET(ret);
15 if (0 == (ifd_pos & 1)) {
16 ret.returncode = is_valid;
17 return ret;
18 } else {
19 // FIXME: tif_fails?
20 ret = set_value_found_ret_formatted_with_returncode(&ret, ifderror_offset_not_word_aligned, "offset of tag-ifd (%lu) points to 0x%08x and is not word-aligned", tag, ifd_pos);
21 return ret;
22 }
23 }
24
25 static ret_t check_first_ifd_word_aligned(uint32 ifd_pos) {
26 GET_EMPTY_RET(ret);
27 if (0 == (ifd_pos & 1)) {
28 ret.returncode = is_valid;
29 return ret;
30 } else {
31 // FIXME: tif_fails?
32 ret = set_value_found_ret_formatted_with_returncode(&ret, ifderror_offset_not_word_aligned, "offset of first ifd points to 0x%08x and is not word-aligned", ifd_pos);
33 return ret;
34 }
35 }
36
37 /* check if IFDs are word aligned */
38 ret_t check_all_IFDs_are_word_aligned(ctiff_t *ctif) {
39 TIFP_CHECK( ctif, ret);
40 uint32 ifd = get_ifd0_pos( ctif );
41 uint16 count = get_ifd0_count( ctif);
42 for (uint16 tagidx = 0; tagidx< count; tagidx++) {
43 ifd_entry_t ifd_entry = TIFFGetRawTagIFDListEntry(ctif, ctif->ifd0, tagidx);
44 if (ifd_entry.datatype == TIFF_IFD || ifd_entry.datatype == TIFF_IFD8) {
45 uint32 offset = ifd_entry.data32offset;
46 tag_t tag = TIFFGetRawTagListEntry( ctif, ctif->ifd0, tagidx);
47 ret_t ret = check_specific_ifd_word_aligned(offset, tag);
48 if (ret.returncode != is_valid ) { return ret; }
49 }
50 }
51 return check_first_ifd_word_aligned(ifd);
52 }
53 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 smarttab expandtab :*/