Repository navigation
Check the inline range before casting style values to int32 - #2075
Open
ZainnQureshii wants to merge 1 commit into
Open
ZainnQureshii wants to merge 1 commit into
ZainnQureshii wants to merge 1 commit into
Conversation
isIntegerPackable cast the float to int32_t before checking that it fits the inline range, which is undefined for values outside int32 (and for infinity and NaN). Check the range on the float first, then cast to test that it is an integer.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
StyleValuePool::isIntegerPackable(yoga/style/StyleValuePool.h) casts the float toint32_tbefore checking that it fits the inline range:Converting a float that is outside the
int32_trange (or infinite, or NaN) toint32_tis undefined behaviour, and every newly stored style length, size or number whose handle is not already indexed into the buffer goes through this check, so a value such as2147483648,FLT_MAXor an infinite number hits it. The fix checks the range on the float first and only then casts to test that the value is an integer, so the cast only ever sees values in-2047..2047. Values that fit are packed exactly as before.No wrong layout is claimed for an ordinary build (checked with Apple Clang on arm64); the problem shows up under
-fsanitize=float-cast-overflow, which aborts while storing those values.Tests
Two new cases in
tests/StyleValuePoolTest.cppstore out-of-range finite values (2147483648,-4294967296,±FLT_MAX) as points, percent and numbers, and±infinityas numbers, and read them back.Built with
-DCMAKE_CXX_FLAGS=-fsanitize=float-cast-overflow -fno-sanitize-recover=float-cast-overflow, both new tests abort before the fix and pass after it, and the full test binary passes with the fix. Without the sanitizer, the new tests pass both before and after.Changelog:
[General][Fixed] - Fix undefined behavior in Yoga when storing style values outside the 32-bit integer range
Prepared with AI assistance (Claude Code) and reviewed with GitHub Copilot.
🤖 Generated with Claude Code