bfd_get_file_size (bfd *abfd)
{
ufile_ptr file_size, archive_size = (ufile_ptr) -1;
+ unsigned int compression_p2 = 0;
if (abfd->my_archive != NULL
&& !bfd_is_thin_archive (abfd->my_archive))
if (adata != NULL)
{
archive_size = adata->parsed_size;
- /* If the archive is compressed we can't compare against
- file size. */
+ /* If the archive is compressed, assume an element won't
+ expand more than eight times file size. */
if (adata->arch_header != NULL
&& memcmp (((struct ar_hdr *) adata->arch_header)->ar_fmag,
"Z\012", 2) == 0)
- return archive_size;
+ compression_p2 = 3;
abfd = abfd->my_archive;
}
}
- file_size = bfd_get_size (abfd);
+ file_size = bfd_get_size (abfd) << compression_p2;
if (archive_size < file_size)
return archive_size;
return file_size;
size_t symesz;
size_t size;
void * syms;
+ ufile_ptr filesize;
if (obj_coff_external_syms (abfd) != NULL)
return true;
if (size == 0)
return true;
+ filesize = bfd_get_file_size (abfd);
+ if (filesize != 0
+ && ((ufile_ptr) obj_sym_filepos (abfd) > filesize
+ || size > filesize - obj_sym_filepos (abfd)))
+ {
+ bfd_set_error (bfd_error_file_truncated);
+ return false;
+ }
+
if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
return false;
syms = _bfd_malloc_and_read (abfd, size, size);