Changeset 272909 in webkit


Ignore:
Timestamp:
Feb 16, 2021 9:26:02 AM (17 months ago)
Author:
weinig@apple.com
Message:

lab() and lch() are not clamping out of bounds values at parse time
https://bugs.webkit.org/show_bug.cgi?id=221947

Reviewed by Simon Fraser.

The model level assertions caught this (yay). The spec requires that we
clamp negative lightness values to 0 for lab(), lch() and color(lab)
and negative chroma values to 0 for lch().

Source/WebCore:

  • css/parser/CSSPropertyParserHelpers.cpp:

(WebCore::CSSPropertyParserHelpers::parseLabParameters):
(WebCore::CSSPropertyParserHelpers::parseLCHParameters):
(WebCore::CSSPropertyParserHelpers::parseColorFunctionForLabParameters):

LayoutTests:

  • fast/css/parsing-lab-colors-expected.txt:
  • fast/css/parsing-lab-colors.html:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r272907 r272909  
     12021-02-16  Sam Weinig  <weinig@apple.com>
     2
     3        lab() and lch() are not clamping out of bounds values at parse time
     4        https://bugs.webkit.org/show_bug.cgi?id=221947
     5
     6        Reviewed by Simon Fraser.
     7
     8        The model level assertions caught this (yay). The spec requires that we
     9        clamp negative lightness values to 0 for lab(), lch() and color(lab)
     10        and negative chroma values to 0 for lch().
     11
     12        * fast/css/parsing-lab-colors-expected.txt:
     13        * fast/css/parsing-lab-colors.html:
     14
    1152021-02-16  Chris Gambrell  <cgambrell@apple.com>
    216
  • trunk/LayoutTests/fast/css/parsing-lab-colors-expected.txt

    r271866 r272909  
    1616PASS computedStyle("background-color", "lab(0% 0 0 / 110%)") is "lab(0% 0 0)"
    1717PASS computedStyle("background-color", "lab(0% 0 0 / 300%)") is "lab(0% 0 0)"
     18PASS computedStyle("background-color", "lab(-40% 0 0)") is "lab(0% 0 0)"
     19PASS computedStyle("background-color", "lab(50% -20 0)") is "lab(50% -20 0)"
     20PASS computedStyle("background-color", "lab(50% 0 -20)") is "lab(50% 0 -20)"
    1821
    1922lch()
     
    3134PASS computedStyle("background-color", "lch(10% 20 740deg)") is "lab(10% 18.793852 6.8404026)"
    3235PASS computedStyle("background-color", "lch(10% 20 -700deg)") is "lab(10% 18.793852 6.8404026)"
     36PASS computedStyle("background-color", "lch(-40% 0 0)") is "lab(0% 0 0)"
     37PASS computedStyle("background-color", "lch(20% -20 0)") is "lab(20% 0 0)"
    3338PASS computedStyle("background-color", "lch(0% 0 0 / 0.5)") is "lab(0% 0 0 / 0.5)"
    3439PASS computedStyle("background-color", "lch(10% 20 20 / 110%)") is "lab(10% 18.793852 6.8404026)"
     
    5358PASS computedStyle("background-color", "color(lab 50% / 0.5)") is "lab(50% 0 0 / 0.5)"
    5459PASS computedStyle("background-color", "color(lab / 0.5)") is "lab(0% 0 0 / 0.5)"
     60PASS computedStyle("background-color", "color(lab -40% 0 0)") is "lab(0% 0 0)"
     61PASS computedStyle("background-color", "color(lab 50% -20 0)") is "lab(50% -20 0)"
     62PASS computedStyle("background-color", "color(lab 50% 0 -20)") is "lab(50% 0 -20)"
    5563
    5664Test invalid values
  • trunk/LayoutTests/fast/css/parsing-lab-colors.html

    r271866 r272909  
    4747    testComputed("background-color", "lab(0% 0 0 / 110%)", "lab(0% 0 0)");
    4848    testComputed("background-color", "lab(0% 0 0 / 300%)", "lab(0% 0 0)");
     49    testComputed("background-color", "lab(-40% 0 0)", "lab(0% 0 0)");
     50    testComputed("background-color", "lab(50% -20 0)", "lab(50% -20 0)");
     51    testComputed("background-color", "lab(50% 0 -20)", "lab(50% 0 -20)");
    4952
    5053    debug('');
     
    6366    testComputed("background-color", "lch(10% 20 740deg)", "lab(10% 18.793852 6.8404026)");
    6467    testComputed("background-color", "lch(10% 20 -700deg)", "lab(10% 18.793852 6.8404026)");
     68    testComputed("background-color", "lch(-40% 0 0)", "lab(0% 0 0)");
     69    testComputed("background-color", "lch(20% -20 0)", "lab(20% 0 0)");
    6570    // hue (the third argument) can be either an angle or number, with number interpreted as degrees.
    6671    testComputed("background-color", "lch(0% 0 0 / 0.5)", "lab(0% 0 0 / 0.5)");
     
    8792    testComputed("background-color", "color(lab 50% / 0.5)", "lab(50% 0 0 / 0.5)");
    8893    testComputed("background-color", "color(lab / 0.5)", "lab(0% 0 0 / 0.5)");
     94    testComputed("background-color", "color(lab -40% 0 0)", "lab(0% 0 0)");
     95    testComputed("background-color", "color(lab 50% -20 0)", "lab(50% -20 0)");
     96    testComputed("background-color", "color(lab 50% 0 -20)", "lab(50% 0 -20)");
    8997
    9098    debug('');
  • trunk/Source/WebCore/ChangeLog

    r272908 r272909  
     12021-02-16  Sam Weinig  <weinig@apple.com>
     2
     3        lab() and lch() are not clamping out of bounds values at parse time
     4        https://bugs.webkit.org/show_bug.cgi?id=221947
     5
     6        Reviewed by Simon Fraser.
     7
     8        The model level assertions caught this (yay). The spec requires that we
     9        clamp negative lightness values to 0 for lab(), lch() and color(lab)
     10        and negative chroma values to 0 for lch().
     11
     12        * css/parser/CSSPropertyParserHelpers.cpp:
     13        (WebCore::CSSPropertyParserHelpers::parseLabParameters):
     14        (WebCore::CSSPropertyParserHelpers::parseLCHParameters):
     15        (WebCore::CSSPropertyParserHelpers::parseColorFunctionForLabParameters):
     16
    1172021-02-16  Alex Christensen  <achristensen@webkit.org>
    218
  • trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp

    r272876 r272909  
    927927        return { };
    928928
    929     return Lab<float> { static_cast<float>(*lightness), static_cast<float>(*aValue), static_cast<float>(*bValue), static_cast<float>(*alpha) };
     929    auto normalizedLightness = std::max(0.0, *lightness);
     930
     931    return Lab<float> { static_cast<float>(normalizedLightness), static_cast<float>(*aValue), static_cast<float>(*bValue), static_cast<float>(*alpha) };
    930932}
    931933
     
    954956        return { };
    955957
     958    auto normalizedLightness = std::max(0.0, *lightness);
     959    auto normalizedChroma = std::max(0.0, *chroma);
    956960    auto normalizedHue = normalizeHue(*hue);
    957961
    958     return convertColor<Lab<float>>(LCHA<float> { static_cast<float>(*lightness), static_cast<float>(*chroma), static_cast<float>(normalizedHue), static_cast<float>(*alpha) });
     962    return convertColor<Lab<float>>(LCHA<float> { static_cast<float>(normalizedLightness), static_cast<float>(normalizedChroma), static_cast<float>(normalizedHue), static_cast<float>(*alpha) });
    959963}
    960964
     
    10061010        return { };
    10071011
    1008     return Lab<float> { static_cast<float>(channels[0]), static_cast<float>(channels[1]), static_cast<float>(channels[2]), static_cast<float>(*alpha) };
     1012    auto normalizedLightness = std::max(0.0, channels[0]);
     1013
     1014    return Lab<float> { static_cast<float>(normalizedLightness), static_cast<float>(channels[1]), static_cast<float>(channels[2]), static_cast<float>(*alpha) };
    10091015}
    10101016
Note: See TracChangeset for help on using the changeset viewer.