Bug 25191 - binutils/strip-new: BFD (GNU Binutils) 2.33 internal error, aborting at elf.c:9101 in _bfd_elf_set_section_contents
Summary: binutils/strip-new: BFD (GNU Binutils) 2.33 internal error, aborting at elf.c...
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.33
: P2 normal
Target Milestone: 2.34
Assignee: Alan Modra
Depends on:
Reported: 2019-11-14 17:02 UTC by chien_hsiang
Modified: 2019-11-19 06:41 UTC (History)
0 users

See Also:
Last reconfirmed: 2019-11-19 00:00:00

file that reproduces this problem (2.66 KB, application/x-ms-dos-executable)
2019-11-14 17:02 UTC, chien_hsiang

Note You need to log in before you can comment on or make changes to this bug.
Description chien_hsiang 2019-11-14 17:02:20 UTC
Created attachment 12074 [details]
file that reproduces this problem

corrupted file can trigger the abort

Version : 2.33.1 (https://ftp.yzu.edu.tw/pub/gnu/binutils/binutils-2.33.1.tar.xz)

Steps to Reproduce :
download the sample from attachment

strip-new  -D -F elf64-x86-64 ./abort_sample
strip-new  -U -F elf64-x86-64 ./abort_sample
strip-new  --remove-relocations .text -F elf32-i386 ./abort_sample

OS : ubuntu 18.04.3
kernel : gnu/linux 5.0.0-32-generic
processor : Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz

Actual Results: the application abort

Expected Results: do not abort
(ex: strip-new -F pei-i386 ./abort_sample)
Comment 1 cvs-commit@gcc.gnu.org 2019-11-19 06:21:30 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:


commit dd68a12bc4b19c50c31fe357335bb8ee9a3322fc
Author: Alan Modra <amodra@gmail.com>
Date:   Tue Nov 19 14:53:44 2019 +1030

    PR25191, internal error in _bfd_elf_set_section_contents
    This PR copies a fuzzed PE input file to ELF output, in the process
    confusing the ELF backend by copying COFF-only section flags to the
    output.  SEC_COFF_SHARED has the same value as SEC_ELF_COMPRESS.  One
    approach to fixing this problem is of course not to reuse flag bits,
    but we've run out.  So this patch only copies section flags that are
    in the bfd_applicable_section_flags set when changing the flavour of
    the output file.
    	PR 25191
    	* objcopy.c (is_nondebug_keep_contents_section): Use bfd_get_flavour.
    	(copy_object): Likewise.
    	(setup_section): Likewise.  If flavour of input and output files
    	differ, restrict section flags to the intersection of input and
    	output bfd_applicable_section_flags.
Comment 2 Alan Modra 2019-11-19 06:41:02 UTC