/* Mach-O support for BFD.
- Copyright (C) 1999-2021 Free Software Foundation, Inc.
+ Copyright (C) 1999-2022 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
#define bfd_mach_o_mkobject bfd_mach_o_gen_mkobject
#define FILE_ALIGN(off, algn) \
- (((off) + ((file_ptr) 1 << (algn)) - 1) & ((file_ptr) -1U << (algn)))
+ (((off) + ((ufile_ptr) 1 << (algn)) - 1) & ((ufile_ptr) -1 << (algn)))
static bool
bfd_mach_o_read_dyld_content (bfd *abfd, bfd_mach_o_dyld_info_command *cmd);
return true;
}
-static INLINE bool
+static inline bool
mach_o_wide_p (bfd_mach_o_header *header)
{
switch (header->version)
}
}
-static INLINE bool
+static inline bool
bfd_mach_o_wide_p (bfd *abfd)
{
return mach_o_wide_p (&bfd_mach_o_get_data (abfd)->header);
return -1;
}
#endif
- return (asect->reloc_count + 1) * sizeof (arelent *);
+ return (asect->reloc_count + 1L) * sizeof (arelent *);
}
/* In addition to the need to byte-swap the symbol number, the bit positions
section->offset = bfd_h_get_32 (abfd, raw.offset);
section->align = bfd_h_get_32 (abfd, raw.align);
/* PR 17512: file: 0017eb76. */
- if (section->align > 64)
+ if (section->align >= 31)
{
_bfd_error_handler
- (_("bfd_mach_o_read_section_32: overlarge alignment value: %#lx, "
- "using 32 instead"), section->align);
- section->align = 32;
+ (_("bfd_mach_o_read_section_32: overlarge alignment value: %#lx"),
+ section->align);
+ section->align = 30;
}
section->reloff = bfd_h_get_32 (abfd, raw.reloff);
section->nreloc = bfd_h_get_32 (abfd, raw.nreloc);
section->size = bfd_h_get_64 (abfd, raw.size);
section->offset = bfd_h_get_32 (abfd, raw.offset);
section->align = bfd_h_get_32 (abfd, raw.align);
- if (section->align > 64)
+ if (section->align >= 63)
{
_bfd_error_handler
- (_("bfd_mach_o_read_section_64: overlarge alignment value: %#lx, "
- "using 32 instead"), section->align);
- section->align = 32;
+ (_("bfd_mach_o_read_section_64: overlarge alignment value: %#lx"),
+ section->align);
+ section->align = 62;
}
section->reloff = bfd_h_get_32 (abfd, raw.reloff);
section->nreloc = bfd_h_get_32 (abfd, raw.nreloc);
struct mach_o_fat_header_external hdr;
unsigned long i;
size_t amt;
+ ufile_ptr filesize;
if (bfd_seek (abfd, 0, SEEK_SET) != 0
|| bfd_bread (&hdr, sizeof (hdr), abfd) != sizeof (hdr))
if (adata->archentries == NULL)
goto error;
+ filesize = bfd_get_file_size (abfd);
for (i = 0; i < adata->nfat_arch; i++)
{
struct mach_o_fat_arch_external arch;
adata->archentries[i].offset = bfd_getb32 (arch.offset);
adata->archentries[i].size = bfd_getb32 (arch.size);
adata->archentries[i].align = bfd_getb32 (arch.align);
+ if (filesize != 0
+ && (adata->archentries[i].offset > filesize
+ || (adata->archentries[i].size
+ > filesize - adata->archentries[i].offset)))
+ {
+ bfd_release (abfd, adata);
+ bfd_set_error (bfd_error_malformed_archive);
+ return NULL;
+ }
}
abfd->tdata.mach_o_fat_data = adata;