Debian Codegraph @

src/lib/ifdrules/check_all_offsets_are_used_once_only.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
14 /* check if offsets are used only once */
15 ret_t check_all_offsets_are_used_once_only(ctiff_t * ctif) {
16 GET_EMPTY_RET(ret);
17 TIFP_CHECK( ctif, ret);
18 uint16 count = get_ifd0_count( ctif);
19 if (count > 0) {
20 uint16 tagidx;
21 uint32 offsets[ count ];
22 uint32 tags[ count ];
23 int count_of_offsets = 0;
24
25 for (tagidx = 0; tagidx< count; tagidx++) {
26 offsets[ tagidx ] = 0;
27 tags[ tagidx ] = 0;
28 }
29 for (tagidx = 0; tagidx< count; tagidx++) {
30 ifd_entry_t ifd_entry = TIFFGetRawTagIFDListEntry( ctif, ctif->ifd0, tagidx );
31 if (ifd_entry.value_or_offset==is_offset) {
32 uint32 offset = ifd_entry.data32offset;
33 tag_t tag = TIFFGetRawTagListEntry( ctif, ctif->ifd0, tagidx);
34 for (int i=0; i< count_of_offsets; i++) {
35 if (offsets[ i ] == offset) {
36 // FIXME: tif_fails?
37 ret = set_value_found_ret_formatted_with_returncode(&ret,ifderror_offset_used_twice, "offset of tag %u (%s) points to %08x, which address is used previously by tag %u (%s)", tag, TIFFTagName(tag), offset, tags[i], TIFFTagName(tags[i]) );
38 return ret;
39 }
40 }
41 offsets[ ++count_of_offsets ] = offset;
42 tags[ count_of_offsets ] = tag;
43 }
44 }
45 }
46 ret.returncode=is_valid; /* valid also if count=0 */
47 return ret;
48 }
49
50
51 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 smarttab expandtab :*/