bfd: Avoid signed overflow for new_size adjustment
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 6 Dec 2022 20:54:43 +0000 (12:54 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 6 Dec 2022 22:47:44 +0000 (14:47 -0800)
commite25466730d436937e814f80b69e5d124513fff03
tree2f1e54e0ea43df62e47d9f003900d604d88d38d1
parent53fd08b60d8183af2a6a6820677bfd01716bc992
bfd: Avoid signed overflow for new_size adjustment

When bfd_size_type is unsigned 64-bit integer and sizeof is unsigned
32-bit integer, subtraction in

*new_size += sizeof (Elf32_External_Chdr) - sizeof (Elf64_External_Chdr);

will overflow.  Use

*new_size -= sizeof (Elf64_External_Chdr) - sizeof (Elf32_External_Chdr);

to avoid overflow.

PR binutils/29860
* compress.c (bfd_convert_section_setup): Avoid signed overflow
for new_size adjustment.
bfd/compress.c