Validate section patch sizes in case object files are invalid (#2242)

This commit is contained in:
Rangi authored and GitHub committed 2026-11-15 01:50:34 +01:00
1 parent a2086efa50
commit bec11bcaa7
3 files changed
+22 -10

No files matched your search

+9
View File
@@ -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
View File
@@ -560,15 +560,7 @@ static void applyFilePatches(Section &section, 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,