Guard against invalid alignment offsets in corrupt object files

This commit is contained in:
Rangi committed 2026-11-24 20:54:46 -05:00
1 parent 18a6f8b12e
commit c459913f87
2 files changed
+7 -4

No files matched your search

+5 -2
View File
@@ -275,9 +275,12 @@ static void readSection(
tryReadLong(
tmp, file, "%s: Cannot read \"%s\"'s alignment offset: %s", fileName, section.name.c_str()
);
if (tmp > UINT16_MAX) {
error("\"%s\"'s alignment offset is too large ($%" PRIx32 ")", section.name.c_str(), tmp);
if (tmp < 0 || tmp > UINT16_MAX) {
error("\"%s\"'s alignment offset is invalid ($%" PRIx32 ")", section.name.c_str(), tmp);
tmp = UINT16_MAX;
} else if (section.isAlignFixed && static_cast<uint32_t>(tmp) > section.alignMask) {
error("\"%s\"'s alignment offset is too large ($%" PRIx32 ")", section.name.c_str(), tmp);
tmp = 0;
}
section.alignOfs = tmp;
+2 -2
View File
@@ -11,8 +11,8 @@
#include <variant>
#include <vector>
#include "backtrace.hpp" // assume
#include "helpers.hpp" // assume
#include "backtrace.hpp"
#include "helpers.hpp" // assume
#include "linkdefs.hpp"
#include "link/fstack.hpp"