fix(il2cpp): validate structural record extents (#7861)

This commit is contained in:
morluto authored and GitHub committed 2026-10-29 01:55:47 +08:00
1 parent 5119d08daf
commit 183e2e2d1e
6 files changed
+227 -81

No files matched your search

+20
View File
@@ -38,6 +38,25 @@ export class Il2cppMetadataFormatFailure extends Error {
}
}
/** Validate a section against a known serialized record width once. */
export const checkedSectionCount = (
section: Il2cppMetadataSection,
recordBytes: number,
): number => {
if (section.size % recordBytes !== 0)
throw new Il2cppMetadataFormatFailure(
"record-size-mismatch",
`section ${section.name} size ${section.size} is not a whole multiple of its ${recordBytes}-byte records`,
);
const count = section.size / recordBytes;
if (section.count !== null && count !== section.count)
throw new Il2cppMetadataFormatFailure(
"record-size-mismatch",
`section ${section.name} size ${section.size} does not hold ${section.count} ${recordBytes}-byte records`,
);
return count;
};
export const checkRange = (
label: string,
start: number,
@@ -64,3 +83,4 @@ export const readIndex = (bytes: Buffer, offset: number, width: 1 | 2 | 4) => {
}
return bytes.readInt32LE(offset);
};
import type { Il2cppMetadataSection } from "../domain/il2cpp/il2cppMetadata.js";