mirror of
https://github.com/gbdev/rgbds.git
synced 2026-11-29 23:08:39 +00:00
Guard against invalid alignment offsets in corrupt object files
This commit is contained in:
1 parent
18a6f8b12e
commit
c459913f87
2 files changed
+7
-4
No files matched your search
+5
-2
@@ -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
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user