Fix 32-bit build warnings

This commit is contained in:
Přemysl Eric Janouch 2023-06-23 13:34:59 +02:00
parent 2dc4e9c13b
commit 4f57070e27
Signed by: p
GPG Key ID: A0420B94F92B9493
2 changed files with 11 additions and 5 deletions

View File

@ -1263,7 +1263,7 @@ parse_mpf_index_ifd(struct tiffer *T)
static bool static bool
parse_mpf( parse_mpf(
GPtrArray *individuals, const uint8_t *mpf, size_t len, const uint8_t *end) GPtrArray *individuals, const uint8_t *mpf, size_t len, size_t total_len)
{ {
struct tiffer T; struct tiffer T;
if (!tiffer_init(&T, mpf, len) || !tiffer_next_ifd(&T)) if (!tiffer_init(&T, mpf, len) || !tiffer_next_ifd(&T))
@ -1274,7 +1274,7 @@ parse_mpf(
uint32_t *offsets = parse_mpf_index_ifd(&T); uint32_t *offsets = parse_mpf_index_ifd(&T);
if (offsets) { if (offsets) {
for (const uint32_t *o = offsets; *o; o++) for (const uint32_t *o = offsets; *o; o++)
if (*o <= end - mpf) if (*o <= total_len)
g_ptr_array_add(individuals, (gpointer) mpf + *o); g_ptr_array_add(individuals, (gpointer) mpf + *o);
free(offsets); free(offsets);
} }
@ -1378,7 +1378,7 @@ parse_jpeg_metadata(const char *data, size_t len, struct jpeg_metadata *meta)
if (meta->mpf && marker == APP2 && p - payload >= 8 && if (meta->mpf && marker == APP2 && p - payload >= 8 &&
!memcmp(payload, "MPF\0", 4) && !meta->mpf->len) { !memcmp(payload, "MPF\0", 4) && !meta->mpf->len) {
payload += 4; payload += 4;
parse_mpf(meta->mpf, payload, p - payload, end); parse_mpf(meta->mpf, payload, p - payload, end - payload);
} }
// TODO(p): Extract the main XMP segment. // TODO(p): Extract the main XMP segment.

View File

@ -156,12 +156,18 @@ tiffer_next_ifd(struct tiffer *self)
return tiffer_u16(self, &self->remaining_fields); return tiffer_u16(self, &self->remaining_fields);
} }
static size_t
tiffer_length(const struct tiffer *self)
{
return self->begin > self->end ? 0 : self->end - self->begin;
}
/// Initialize a derived TIFF reader for a subIFD at the given location. /// Initialize a derived TIFF reader for a subIFD at the given location.
static bool static bool
tiffer_subifd( tiffer_subifd(
const struct tiffer *self, uint32_t offset, struct tiffer *subreader) const struct tiffer *self, uint32_t offset, struct tiffer *subreader)
{ {
if (self->begin > self->end || self->end - self->begin < offset) if (tiffer_length(self) < offset)
return false; return false;
*subreader = *self; *subreader = *self;
@ -332,7 +338,7 @@ tiffer_next_entry(struct tiffer *self, struct tiffer_entry *entry)
if (values_size <= sizeof offset) { if (values_size <= sizeof offset) {
entry->p = self->p; entry->p = self->p;
self->p += sizeof offset; self->p += sizeof offset;
} else if (tiffer_u32(self, &offset) && self->end - self->begin >= offset) { } else if (tiffer_u32(self, &offset) && tiffer_length(self) >= offset) {
entry->p = self->begin + offset; entry->p = self->begin + offset;
} else { } else {
return false; return false;