Browse Source

- optimized includes

- fixed types and type casts
- fixed bug in scan_mem_map() using count of size uint32 instead uint16
development
Andreas Romeyke 8 months ago
parent
commit
bee151895b
1 changed files with 16 additions and 17 deletions
  1. +16
    -17
      src/risk_analyzer/lst_offset_mappings.c

+ 16
- 17
src/risk_analyzer/lst_offset_mappings.c View File

@ -8,7 +8,6 @@
#include "check.h"
#include "check_helper.h"
#include <unistd.h>
#include <assert.h>
@ -59,9 +58,9 @@ mem_map_t * scan_mem_map(ctiff_t * ctif) {
/* iterate through IFD0 entries */
uint16 tagidx;
for (tagidx = 0; tagidx< ifdcount; tagidx++) {
add_mem_entry( &memmap, ifdbase+(tagidx*12), 8, mt_ifd); /* tagid, field type, count */
add_mem_entry(&memmap, (uint32) (ifdbase + (tagidx * 12)), 8, mt_ifd); /* tagid, field type, count */
ifd_entry_t ifd_entry = TIFFGetRawTagIFDListEntry( ctif, tagidx );
uint32 tag = TIFFGetRawTagListEntry( ctif, tagidx);
tag_t tag = TIFFGetRawTagListEntry( ctif, tagidx);
TIFFDataType datatype = TIFFGetRawTagType( ctif, tag);
int datasize;
switch (datatype) {
@ -80,14 +79,14 @@ mem_map_t * scan_mem_map(ctiff_t * ctif) {
default: fprintf(stderr, "unknown datatype %i, possible a program error", datatype); exit(EXIT_FAILURE);
}
uint32 offset = ifd_entry.data32offset;
uint16 count = ifd_entry.count;
uint32 count = ifd_entry.count;
if (tag == TIFFTAG_STRIPOFFSETS) {
if (ifd_entry.value_or_offset == is_offset) {
add_mem_entry( &memmap, ifdbase+(tagidx*12)+8,4,mt_ifd_offset_to_standardized_value );
add_mem_entry(&memmap, (uint32) (ifdbase + (tagidx * 12) + 8), 4, mt_ifd_offset_to_standardized_value );
add_mem_entry( &memmap, offset, ((uint32) count)*datasize, mt_ifd_offset_to_stripoffsets );
} else if (ifd_entry.value_or_offset==is_value) {
add_mem_entry( &memmap, ifdbase+(tagidx*12)+8, 4,mt_ifd_embedded_standardized_value );
add_mem_entry(&memmap, (uint32) (ifdbase + (tagidx * 12) + 8), 4, mt_ifd_embedded_standardized_value );
}
/*
ifd_entry_t stripoffset_entry;
@ -175,22 +174,22 @@ mem_map_t * scan_mem_map(ctiff_t * ctif) {
} else if (ifd_entry.value_or_offset==is_offset) { /* offset */
if (tag < 32768) { /* standard tag */
add_mem_entry( &memmap, ifdbase+(tagidx*12)+8, 4,mt_ifd_offset_to_standardized_value );
add_mem_entry(&memmap, (uint32) (ifdbase + (tagidx * 12) + 8), 4, mt_ifd_offset_to_standardized_value );
add_mem_entry( &memmap, offset, ((uint32) count)*datasize, mt_standardized_value );
} else if (tag < 65000) { /* registered tag */
add_mem_entry( &memmap, ifdbase+(tagidx*12)+8, 4,mt_ifd_offset_to_registered_value );
add_mem_entry(&memmap, (uint32) (ifdbase + (tagidx * 12) + 8), 4, mt_ifd_offset_to_registered_value );
add_mem_entry( &memmap, offset, ((uint32) count)*datasize, mt_registered_value );
} else { /* private tag */
add_mem_entry( &memmap, ifdbase+(tagidx*12)+8, 4,mt_ifd_offset_to_private_value );
add_mem_entry(&memmap, (uint32) (ifdbase + (tagidx * 12) + 8), 4, mt_ifd_offset_to_private_value );
add_mem_entry( &memmap, offset, ((uint32) count)*datasize, mt_private_value );
}
} else if (ifd_entry.value_or_offset==is_value) { /* embedded value */
if (tag < 32768) { /* standard tag */
add_mem_entry( &memmap, ifdbase+(tagidx*12)+8, 4,mt_ifd_embedded_standardized_value );
add_mem_entry(&memmap, (uint32) (ifdbase + (tagidx * 12) + 8), 4, mt_ifd_embedded_standardized_value );
} else if (tag < 65000) { /* registered tag */
add_mem_entry( &memmap, ifdbase+(tagidx*12)+8, 4,mt_ifd_embedded_registered_value );
add_mem_entry(&memmap, (uint32) (ifdbase + (tagidx * 12) + 8), 4, mt_ifd_embedded_registered_value );
} else { /* private tag */
add_mem_entry( &memmap, ifdbase+(tagidx*12)+8, 4,mt_ifd_embedded_private_value );
add_mem_entry(&memmap, (uint32) (ifdbase + (tagidx * 12) + 8), 4, mt_ifd_embedded_private_value );
}
}
@ -200,10 +199,10 @@ mem_map_t * scan_mem_map(ctiff_t * ctif) {
// uint32 offset = get_ifd0_pos(ctif );
// uint32 IFDn = get_next_ifd_pos( ctif, offset );
// printf("IFD: offset=%i, IFD0=%i IFDn=%i ifd+count=%i\n", offset, ifd, IFDn, ifdbase+12*count);
add_mem_entry( &memmap, ifdbase+12*ifdcount, 4, mt_offset_to_ifd);
add_mem_entry(&memmap, (uint32) (ifdbase + 12 * ifdcount), 4, mt_offset_to_ifd);
/* sort entries by offset */
qsort(memmap.base_p, memmap.count, sizeof( mem_map_entry_t), compare_memmap);
qsort(memmap.base_p, (size_t) memmap.count, sizeof( mem_map_entry_t), compare_memmap);
/*
printf("memmap before HOLE detection\n");
print_mem_map( &memmap );
@ -211,7 +210,7 @@ mem_map_t * scan_mem_map(ctiff_t * ctif) {
*/
/* add all unused areas */
uint32 memmap_orig_count = memmap.count;
uint32 memmap_orig_count = (uint32) 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;
@ -224,7 +223,7 @@ mem_map_t * scan_mem_map(ctiff_t * ctif) {
}
}
/* sort entries by offset again */
qsort(memmap.base_p, memmap.count, sizeof( mem_map_entry_t), compare_memmap);
qsort(memmap.base_p, (size_t) memmap.count, sizeof( mem_map_entry_t), compare_memmap);
/* add unused area at end */
mem_map_entry_t * last = memmap.base_p + memmap.count-1;
uint32 estimated_offset = (last->offset + last->count);
@ -233,7 +232,7 @@ mem_map_t * scan_mem_map(ctiff_t * ctif) {
add_mem_entry( &memmap, estimated_offset, (memmap.max_len -estimated_offset), mt_unused);
}
/* sort entries by offset again */
qsort(memmap.base_p, memmap.count, sizeof( mem_map_entry_t), compare_memmap);
qsort(memmap.base_p, (size_t) memmap.count, sizeof( mem_map_entry_t), compare_memmap);
return &memmap;
}


Loading…
Cancel
Save