Fix XCOFF armap traversal to prevent out-of-bounds reads
Corrects XCOFF armap processing in binutils to prevent memory errors.
This commit fixes a bug in binutils’ handling of XCOFF armap symbol names that could lead to out-of-bounds reads or buffer overflows. The xcoff_write_armap_big function in coff-rs6000.c has been modified to correctly check the armap count within its loops, ensuring that it does not read past the allocated buffer when matching symbol names against BFD archives.
In Details
The xcoff_write_armap_big function in bfd/coff-rs6000.c processes XCOFF armap symbol names. An OSS-Fuzz report indicated that the loop condition for iterating through the map array was insufficient, allowing i to exceed orl_count in certain cases. This patch corrects the loop conditions to ensure that i is always less than orl_count before accessing map[i], preventing potential uninitialized reads or buffer overflows.
- XCOFF
- Extended Common Object File Format, a variant of COFF used on IBM RS/6000 and other systems.
- armap
- A symbol table extension in XCOFF that maps archive member names to their BFD structures.
- BFD
- Binary File Descriptor library, a low-level library used by binutils to read and write object file formats.
- OSS-Fuzz
- A free fuzzing-as-a-service for open-source projects provided by Google.
- buffer overflow
- A condition where a program attempts to write more data to a buffer than it can hold, potentially overwriting adjacent memory.