mirror of
https://github.com/gbdev/rgbds.git
synced 2026-11-29 23:08:39 +00:00
Validate section patch sizes in case object files are invalid (#2242)
This commit is contained in:
1 parent
a2086efa50
commit
bec11bcaa7
3 files changed
+22
-10
No files matched your search
@@ -383,6 +383,15 @@ static void readSection(
|
||||
patch.type = PatchType(type);
|
||||
}
|
||||
|
||||
if (patch.offset > section.size || patch.offset + patch.typeSize() > section.size) {
|
||||
fatal(
|
||||
"%s: \"%s\"'s patch #%" PRIu32 " overflows the section",
|
||||
fileName,
|
||||
section.name.c_str(),
|
||||
patchID
|
||||
);
|
||||
}
|
||||
|
||||
uint32_t rpnSize;
|
||||
tryReadLong(
|
||||
rpnSize,
|
||||
|
||||
+1
-9
@@ -560,15 +560,7 @@ static void applyFilePatches(Section §ion, Section &dataSection) {
|
||||
for (Patch &patch : section.patches) {
|
||||
int32_t value = computeRPNExpr(patch.rpn, *section.fileSymbols);
|
||||
uint32_t offset = patch.offset + section.offset;
|
||||
|
||||
uint8_t typeSizes[PATCHTYPE_INVALID] = {
|
||||
1, // PATCHTYPE_BYTE
|
||||
2, // PATCHTYPE_WORD
|
||||
4, // PATCHTYPE_LONG
|
||||
1, // PATCHTYPE_JR
|
||||
};
|
||||
uint8_t typeSize = typeSizes[patch.type];
|
||||
|
||||
uint8_t typeSize = patch.typeSize();
|
||||
if (dataSection.data.size() < offset + typeSize) {
|
||||
rpnErrorAt(
|
||||
patch.rpn,
|
||||
|
||||
Reference in new issue
Block a user