From: Alan Modra Date: Tue, 28 Dec 2021 12:21:55 +0000 (+1030) Subject: Check thin archive element file size against archive header X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=48e3e6aec8a4f37d00ea6c0da3ab45e76490e3db;p=binutils-gdb.git Check thin archive element file size against archive header Makes it a little less likely for someone to break their thin archives. * archive.c (_bfd_get_elt_at_filepos): Check thin archive element file size. --- diff --git a/bfd/archive.c b/bfd/archive.c index 9ad61adc615..ffaec7e2231 100644 --- a/bfd/archive.c +++ b/bfd/archive.c @@ -717,7 +717,17 @@ _bfd_get_elt_at_filepos (bfd *archive, file_ptr filepos, open the external file as a bfd. */ bfd_set_error (bfd_error_no_error); n_bfd = open_nested_file (filename, archive); - if (n_bfd == NULL) + if (n_bfd != NULL) + { + ufile_ptr size = bfd_get_size (n_bfd); + if (size != 0 && size != new_areldata->parsed_size) + { + bfd_set_error (bfd_error_malformed_archive); + bfd_close (n_bfd); + n_bfd = NULL; + } + } + else { switch (bfd_get_error ()) {