-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
LibWeb/CSS: Fix crash resolving calc
with only percentages
#3007
base: master
Are you sure you want to change the base?
LibWeb/CSS: Fix crash resolving calc
with only percentages
#3007
Conversation
Hi @Jaycadox, thanks for looking into this! Could you also add a test to expose the original issue? |
if (result.type().has_value() && (result.type()->matches_length() || result.type()->matches_percentage())) | ||
return Length::make_px(CSSPixels { result.value() }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't correct. If a percentage gets returned (eg, 35%
) it'll return that number as a length (35px
).
A more correct thing to do would be to return the percentage applied to the percentage_basis
in that case.
The question is why this isn't getting converted to a length earlier on. NumericCalculationNode::resolve()
should be doing that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my analysis, I believe it would actually return the correct resolved pixel value (as percentage_basis
was being called on it in NumericCalculationNode::resolve
), the issue was purely that it was being reported as the wrong type, and I do think that my original patch, did fix the specific issue, but agree that it didn't fix the underlying problem.
233cdb3
to
b307b43
Compare
I had a look again at the issue, it seems that In my new patch, I visit all the variants of the percentage basis and set the As the original code (which I put in my original message) only handles the case of |
24f03a7
to
64566e9
Compare
64566e9
to
9cf2b6c
Compare
static Optional<CSSNumericType> numeric_type_from_calculated_style_value(CalculatedStyleValue::CalculationResult::Value const& value) | ||
{ | ||
return value.visit( | ||
[](Number const&) -> Optional<CSSNumericType> { return {}; }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what CSSNumericType
should occur in the case of Number
, I assume there isn't a set one and it can change. But this code should probably be corrected if there is one.
Fixes #3006 , (relates to) #648
From some analysis, it seems as if this issue only occurs with a only percentages in a
calc
.calc(10%)
crashes.calc(10% + 10%)
crashes.calc(10% + 0px)
doesn't crash.calc(10vw)
doesn't crash.The
resolve
function returns aLength
in the general case, but returns aPercentage
if only percentages are provided.As a sanity check, I looked at the code before it was changed (commit before change was here), and it only handled the case of percentages and lengths, as I do in this commit.
The old code being:
Not sure if this is perfect, very open to constructive criticism.