Skip to content

Commit 004546b

Browse files
committed
bug #2572 [TwigComponent] Fix ComponentTokenParser on 32-bits (smnandre)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [TwigComponent] Fix ComponentTokenParser on 32-bits | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Issues | Fix #2568 | License | MIT - 64-bit users get the original behavior - 32-bit users get the fix to prevent overflow issues Commits ------- 8803614 [TwigComponent] Fix ComponentTokenParser on 32-bits
2 parents cb09dd8 + 8803614 commit 004546b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/TwigComponent/src/Twig/ComponentTokenParser.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ private function generateEmbeddedTemplateIndex(string $file, int $line): int
118118
$this->lineAndFileCounts[$fileAndLine] = 0;
119119
}
120120

121-
return crc32($fileAndLine).++$this->lineAndFileCounts[$fileAndLine];
121+
$index = crc32($fileAndLine).++$this->lineAndFileCounts[$fileAndLine];
122+
123+
if (4 === \PHP_INT_SIZE) {
124+
// On 32-bit PHP, the index can be negative or greater than PHP_INT_MAX
125+
// we need to convert it to a positive 32-bit integer
126+
$index = fmod(abs($index), \PHP_INT_MAX) + 1;
127+
}
128+
129+
return (int) $index;
122130
}
123131
}

0 commit comments

Comments
 (0)