Additional alignment checks in TDF validation

This commit is contained in:
Nav
2025-01-28 00:04:24 +00:00
parent 05938ce0ac
commit 3c1916a0c9
2 changed files with 58 additions and 6 deletions

View File

@@ -358,12 +358,12 @@ class ValidationService
}
if ($segment->pageSize !== null) {
if (($segment->addressRange->startAddress % $segment->pageSize) !== 0) {
$failures[] = 'Start address is not a multiple of the page size';
if (!$this->alignsWith($segment->addressRange->startAddress, $segment->pageSize)) {
$failures[] = 'Start address does not align with the page size';
}
if ($segment->size() !== null && ($segment->size() % $segment->pageSize) !== 0) {
$failures[] = 'Size (' . $segment->size() . ') is not a multiple of the page size ('
if ($segment->size() !== null && !$this->alignsWith($segment->size(), $segment->pageSize)) {
$failures[] = 'Size (' . $segment->size() . ') does not align with the page size ('
. $segment->pageSize . ')';
}
}
@@ -1165,4 +1165,9 @@ class ValidationService
$failures
);
}
protected function alignsWith(int $value, int $alignTo): bool
{
return ($value % $alignTo) === 0;
}
}