diff --git a/src/link/object.cpp b/src/link/object.cpp index 336b176b..d9aaa1a4 100644 --- a/src/link/object.cpp +++ b/src/link/object.cpp @@ -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(tmp) > section.alignMask) { + error("\"%s\"'s alignment offset is too large ($%" PRIx32 ")", section.name.c_str(), tmp); + tmp = 0; } section.alignOfs = tmp; diff --git a/src/link/symbol.cpp b/src/link/symbol.cpp index 39e9505b..c689da8d 100644 --- a/src/link/symbol.cpp +++ b/src/link/symbol.cpp @@ -11,8 +11,8 @@ #include #include -#include "backtrace.hpp" // assume -#include "helpers.hpp" // assume +#include "backtrace.hpp" +#include "helpers.hpp" // assume #include "linkdefs.hpp" #include "link/fstack.hpp"