ld/pdb: Fix PDB source-info substream overflow
Fix overflow in PDB source-info substream by widening source_files_count.
The linker previously used a uint16_t for source_files_count, which counts all source file references across modules. This could wrap around if there were more than 65535 references, leading to an incorrectly sized buffer for the source-info substream and subsequent buffer overflows. This change widens the count to uint32_t to accommodate larger numbers of source files.
In Details
The source_files_count in create_source_info_substream was erroneously defined as uint16_t. This count is derived from the total references across all modules, not a deduplicated count intended for the substream header. A link with > 65535 references would cause this to wrap, leading to a buffer underallocation and overflow. The fix promotes source_files_count to unsigned int (effectively uint32_t on common platforms) to prevent this overflow.
- PDB
- Program Database file. Stores debugging and project-specific information for Microsoft Windows applications. The linker generates PDB files for debugging symbols.
- substream
- A distinct section within a larger data structure or file format. In PDB files, substreams group related information, such as source file details or linker symbols.