Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TwigComponent] ComponentTokenParser failing to generate template index on 32bit platform #2568

Open
smnscp opened this issue Feb 12, 2025 · 3 comments · May be fixed by #2572
Open

[TwigComponent] ComponentTokenParser failing to generate template index on 32bit platform #2568

smnscp opened this issue Feb 12, 2025 · 3 comments · May be fixed by #2572
Labels
Bug Bug Fix Status: Reviewed Has been reviewed by a maintainer TwigComponent

Comments

@smnscp
Copy link

smnscp commented Feb 12, 2025

This issue affects only 32bit platforms.

Appending digits to a 32bit integer in ComponentTokenParser::generateEmbeddedTemplateIndex is prone to integer overflows on 32bit systems, resulting in errors like:

Symfony\UX\TwigComponent\Twig\ComponentTokenParser::generateEmbeddedTemplateIndex(): Return value must be of type int, string returned

I guess, that’s what happened in EasyCorp/EasyAdminBundle#6713

Furthermore, crc32 itself can return negative integers on 32bit which can lead to unexpected results (- in compiled class names).

@smnscp
Copy link
Author

smnscp commented Feb 12, 2025

My naive approach to work around this issue is to make sure the generated index is positive and less than or equal PHP_INT_MAX:

return crc32($fileAndLine).++$this->lineAndFileCounts[$fileAndLine];

        return 1 + fmod(abs(crc32($fileAndLine).++$this->lineAndFileCounts[$fileAndLine]), PHP_INT_MAX);

@smnandre smnandre linked a pull request Feb 12, 2025 that will close this issue
@smnandre
Copy link
Member

Hey @smnscp! Thanks for the report, I just opened a PR, could you check it and see if it solves your problem ?

@smnandre smnandre added Status: Reviewed Has been reviewed by a maintainer TwigComponent and removed Status: Needs Review Needs to be reviewed labels Feb 12, 2025
@smnandre smnandre changed the title TwigComponent: ComponentTokenParser::generateEmbeddedTemplateIndex failing on 32bit platform [TwigComponent] ComponentTokenParser failing to generate template index on 32bit platform Feb 12, 2025
@smnscp
Copy link
Author

smnscp commented Feb 13, 2025

Hi @smnandre, thanks for your quick response and the PR! The code changes (and documentation!) look good to me. I'll apply the patch and run it on that 32-bit machine, just to make sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug Fix Status: Reviewed Has been reviewed by a maintainer TwigComponent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants