Prevent SECTION FRAGMENT combined sizes from overflowing their uint16_t size

This commit is contained in:
Rangi
2026-08-22 18:24:17 -04:00
parent ed0a2d1075
commit 8bc7de35f9
4 changed files with 24 additions and 0 deletions
+9
View File
@@ -146,6 +146,15 @@ static void mergeSections(Section &target, std::unique_ptr<Section> &&other) {
case SECTION_FRAGMENT:
checkPieceCompat(target, *other, target.size);
// Check that `target.size += other->size` below will not overflow
if (target.size + other->size > UINT16_MAX) {
fatalTwoAt(
target,
*other,
"Section \"%s\" fragments combined are larger than the GB address space",
target.name.c_str()
);
}
// Append `other` to `target`
other->offset = target.size;
target.size += other->size;