Title: [283188] trunk
Revision
283188
Author
[email protected]
Date
2021-09-28 12:53:36 -0700 (Tue, 28 Sep 2021)

Log Message

Negative integers in @font-palette-values are invalid
https://bugs.webkit.org/show_bug.cgi?id=230788
<rdar://problem/83528806>

Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

This is being upstreamed at https://github.com/web-platform-tests/wpt/pull/30961.

* web-platform-tests/css/css-fonts/parsing/font-palette-values-invalid-expected.txt:
* web-platform-tests/css/css-fonts/parsing/font-palette-values-invalid.html:
* web-platform-tests/css/css-fonts/parsing/font-palette-values-valid-expected.txt:
* web-platform-tests/css/css-fonts/parsing/font-palette-values-valid.html:

Source/WebCore:

The spec made it illegal in
https://github.com/w3c/csswg-drafts/commit/09b3c45238feb6c0e8526e010cd3780f4fc4900b.

Test: web-platform-tests/css/css-fonts/parsing/font-palette-values-invalid.html

* css/CSSFontPaletteValuesRule.cpp:
(WebCore::CSSFontPaletteValuesRule::basePalette const):
(WebCore::CSSFontPaletteValuesRule::initializeMapLike):
(WebCore::CSSFontPaletteValuesRule::cssText const):
* css/parser/CSSParserImpl.cpp:
(WebCore::CSSParserImpl::consumeFontPaletteValuesRule):
* css/parser/CSSPropertyParser.cpp:
(WebCore::consumeBasePaletteDescriptor):
(WebCore::consumeOverrideColorDescriptor):
* platform/graphics/FontPaletteValues.h:
* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::addAttributesForFontPalettes):

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (283187 => 283188)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-09-28 19:15:02 UTC (rev 283187)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-09-28 19:53:36 UTC (rev 283188)
@@ -1,3 +1,18 @@
+2021-09-28  Myles C. Maxfield  <[email protected]>
+
+        Negative integers in @font-palette-values are invalid
+        https://bugs.webkit.org/show_bug.cgi?id=230788
+        <rdar://problem/83528806>
+
+        Reviewed by Simon Fraser.
+
+        This is being upstreamed at https://github.com/web-platform-tests/wpt/pull/30961.
+
+        * web-platform-tests/css/css-fonts/parsing/font-palette-values-invalid-expected.txt:
+        * web-platform-tests/css/css-fonts/parsing/font-palette-values-invalid.html:
+        * web-platform-tests/css/css-fonts/parsing/font-palette-values-valid-expected.txt:
+        * web-platform-tests/css/css-fonts/parsing/font-palette-values-valid.html:
+
 2021-09-28  Sihui Liu  <[email protected]>
 
         Make StorageManager available in Worker

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-invalid-expected.txt (283187 => 283188)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-invalid-expected.txt	2021-09-28 19:15:02 UTC (rev 283187)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-invalid-expected.txt	2021-09-28 19:53:36 UTC (rev 283188)
@@ -18,4 +18,5 @@
 PASS CSS Fonts Module Level 4: parsing @font-palette-values 16
 PASS CSS Fonts Module Level 4: parsing @font-palette-values 17
 PASS CSS Fonts Module Level 4: parsing @font-palette-values 18
+PASS CSS Fonts Module Level 4: parsing @font-palette-values 19
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-invalid.html (283187 => 283188)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-invalid.html	2021-09-28 19:15:02 UTC (rev 283187)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-invalid.html	2021-09-28 19:53:36 UTC (rev 283188)
@@ -101,6 +101,12 @@
     base-palette: unset;
     override-colors: unset;
 }
+
+/* 17 */
+@font-palette-values A {
+    base-palette: -1;
+    override-color: -1 #123;
+}
 </style>
 </head>
 <body>
@@ -107,7 +113,7 @@
 <script>
 let rules = document.getElementById("style").sheet.cssRules;
 test(function() {
-    assert_equals(rules.length, 17);
+    assert_equals(rules.length, 18);
 });
 
 test(function() {
@@ -252,6 +258,15 @@
 test(function() {
     assert_equals(CSSRule.FONT_PALETTE_VALUES_RULE, undefined);
 });
+
+test(function() {
+    let text = rules[17].cssText;
+    let rule = rules[17];
+    assert_equals(text.indexOf("base-palette"), -1);
+    assert_equals(text.indexOf("override-color"), -1);
+    assert_equals(rule.size, 0);
+    assert_equals(rule.basePalette, "");
+});
 </script>
 </body>
 </html>

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-valid-expected.txt (283187 => 283188)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-valid-expected.txt	2021-09-28 19:15:02 UTC (rev 283187)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-valid-expected.txt	2021-09-28 19:53:36 UTC (rev 283188)
@@ -27,8 +27,4 @@
 PASS CSS Fonts Module Level 4: parsing @font-palette-values 25
 PASS CSS Fonts Module Level 4: parsing @font-palette-values 26
 PASS CSS Fonts Module Level 4: parsing @font-palette-values 27
-PASS CSS Fonts Module Level 4: parsing @font-palette-values 28
-PASS CSS Fonts Module Level 4: parsing @font-palette-values 29
-PASS CSS Fonts Module Level 4: parsing @font-palette-values 30
-PASS CSS Fonts Module Level 4: parsing @font-palette-values 31
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-valid.html (283187 => 283188)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-valid.html	2021-09-28 19:15:02 UTC (rev 283187)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-valid.html	2021-09-28 19:53:36 UTC (rev 283188)
@@ -62,41 +62,31 @@
 
 /* 8 */
 @font-palette-values I {
-    base-palette: -3;
+    override-colors: 0 #0000FF;
 }
 
 /* 9 */
 @font-palette-values J {
-    override-colors: -3 rgb(17, 34, 51);
+    override-colors: 0 green;
 }
 
 /* 10 */
 @font-palette-values K {
-    override-colors: 0 #0000FF;
+    override-colors: 0 transparent;
 }
 
 /* 11 */
 @font-palette-values L {
-    override-colors: 0 green;
+    override-colors: 0 rgba(1 2 3 / 4);
 }
 
 /* 12 */
 @font-palette-values M {
-    override-colors: 0 transparent;
+    override-colors: 0 lab(29.2345% 39.3825 20.0664);
 }
 
 /* 13 */
 @font-palette-values N {
-    override-colors: 0 rgba(1 2 3 / 4);
-}
-
-/* 14 */
-@font-palette-values O {
-    override-colors: 0 lab(29.2345% 39.3825 20.0664);
-}
-
-/* 15 */
-@font-palette-values P {
     override-colors: 0 color(display-p3 100% 100% 100%);
 }
 </style>
@@ -242,7 +232,8 @@
 
 test(function() {
     let text = rules[8].cssText;
-    assert_not_equals(text.indexOf("base-palette"), -1);
+    assert_not_equals(text.indexOf("override-colors"), -1);
+    assert_not_equals(text.indexOf("rgb(0, 0, 255)"), -1);
 });
 
 test(function() {
@@ -249,13 +240,15 @@
     let rule = rules[8];
     assert_equals(rule.name, "I");
     assert_equals(rule.fontFamily, "");
-    assert_equals(rule.basePalette, "-3");
-    assert_equals(rule.size, 0);
+    assert_equals(rule.basePalette, "");
+    assert_equals(rule.size, 1);
+    assert_equals(rule.get(0), "rgb(0, 0, 255)");
 });
 
 test(function() {
     let text = rules[9].cssText;
     assert_not_equals(text.indexOf("override-colors"), -1);
+    assert_not_equals(text.indexOf("rgb(0, 128, 0)"), -1);
 });
 
 test(function() {
@@ -264,14 +257,13 @@
     assert_equals(rule.fontFamily, "");
     assert_equals(rule.basePalette, "");
     assert_equals(rule.size, 1);
-    assert_equals(rule.get(7), undefined);
-    assert_equals(rule.get(-3), undefined);
+    assert_equals(rule.get(0), "rgb(0, 128, 0)");
 });
 
 test(function() {
     let text = rules[10].cssText;
     assert_not_equals(text.indexOf("override-colors"), -1);
-    assert_not_equals(text.indexOf("rgb(0, 0, 255)"), -1);
+    assert_not_equals(text.indexOf("rgba(0, 0, 0, 0)"), -1);
 });
 
 test(function() {
@@ -280,13 +272,13 @@
     assert_equals(rule.fontFamily, "");
     assert_equals(rule.basePalette, "");
     assert_equals(rule.size, 1);
-    assert_equals(rule.get(0), "rgb(0, 0, 255)");
+    assert_equals(rule.get(0), "rgba(0, 0, 0, 0)");
 });
 
 test(function() {
     let text = rules[11].cssText;
     assert_not_equals(text.indexOf("override-colors"), -1);
-    assert_not_equals(text.indexOf("rgb(0, 128, 0)"), -1);
+    assert_not_equals(text.indexOf("2"), -1);
 });
 
 test(function() {
@@ -295,13 +287,13 @@
     assert_equals(rule.fontFamily, "");
     assert_equals(rule.basePalette, "");
     assert_equals(rule.size, 1);
-    assert_equals(rule.get(0), "rgb(0, 128, 0)");
+    assert_not_equals(rule.get(0).indexOf("2"), -1);
 });
 
 test(function() {
     let text = rules[12].cssText;
     assert_not_equals(text.indexOf("override-colors"), -1);
-    assert_not_equals(text.indexOf("rgba(0, 0, 0, 0)"), -1);
+    assert_not_equals(text.indexOf("29"), -1);
 });
 
 test(function() {
@@ -310,13 +302,13 @@
     assert_equals(rule.fontFamily, "");
     assert_equals(rule.basePalette, "");
     assert_equals(rule.size, 1);
-    assert_equals(rule.get(0), "rgba(0, 0, 0, 0)");
+    assert_not_equals(rule.get(0).indexOf("lab"), -1);
 });
 
 test(function() {
     let text = rules[13].cssText;
     assert_not_equals(text.indexOf("override-colors"), -1);
-    assert_not_equals(text.indexOf("2"), -1);
+    assert_not_equals(text.indexOf("display-p3"), -1);
 });
 
 test(function() {
@@ -325,36 +317,6 @@
     assert_equals(rule.fontFamily, "");
     assert_equals(rule.basePalette, "");
     assert_equals(rule.size, 1);
-    assert_not_equals(rule.get(0).indexOf("2"), -1);
-});
-
-test(function() {
-    let text = rules[14].cssText;
-    assert_not_equals(text.indexOf("override-colors"), -1);
-    assert_not_equals(text.indexOf("29"), -1);
-});
-
-test(function() {
-    let rule = rules[14];
-    assert_equals(rule.name, "O");
-    assert_equals(rule.fontFamily, "");
-    assert_equals(rule.basePalette, "");
-    assert_equals(rule.size, 1);
-    assert_not_equals(rule.get(0).indexOf("lab"), -1);
-});
-
-test(function() {
-    let text = rules[15].cssText;
-    assert_not_equals(text.indexOf("override-colors"), -1);
-    assert_not_equals(text.indexOf("display-p3"), -1);
-});
-
-test(function() {
-    let rule = rules[15];
-    assert_equals(rule.name, "P");
-    assert_equals(rule.fontFamily, "");
-    assert_equals(rule.basePalette, "");
-    assert_equals(rule.size, 1);
     assert_not_equals(rule.get(0).indexOf("display-p3"), -1);
 });
 </script>

Modified: trunk/Source/WebCore/ChangeLog (283187 => 283188)


--- trunk/Source/WebCore/ChangeLog	2021-09-28 19:15:02 UTC (rev 283187)
+++ trunk/Source/WebCore/ChangeLog	2021-09-28 19:53:36 UTC (rev 283188)
@@ -1,3 +1,29 @@
+2021-09-28  Myles C. Maxfield  <[email protected]>
+
+        Negative integers in @font-palette-values are invalid
+        https://bugs.webkit.org/show_bug.cgi?id=230788
+        <rdar://problem/83528806>
+
+        Reviewed by Simon Fraser.
+
+        The spec made it illegal in
+        https://github.com/w3c/csswg-drafts/commit/09b3c45238feb6c0e8526e010cd3780f4fc4900b.
+
+        Test: web-platform-tests/css/css-fonts/parsing/font-palette-values-invalid.html
+
+        * css/CSSFontPaletteValuesRule.cpp:
+        (WebCore::CSSFontPaletteValuesRule::basePalette const):
+        (WebCore::CSSFontPaletteValuesRule::initializeMapLike):
+        (WebCore::CSSFontPaletteValuesRule::cssText const):
+        * css/parser/CSSParserImpl.cpp:
+        (WebCore::CSSParserImpl::consumeFontPaletteValuesRule):
+        * css/parser/CSSPropertyParser.cpp:
+        (WebCore::consumeBasePaletteDescriptor):
+        (WebCore::consumeOverrideColorDescriptor):
+        * platform/graphics/FontPaletteValues.h:
+        * platform/graphics/cocoa/FontCacheCoreText.cpp:
+        (WebCore::addAttributesForFontPalettes):
+
 2021-09-28  Youenn Fablet  <[email protected]>
 
         [BigSur wk2 Debug iOS14 ] webrtc/video-mute.html is a flaky failure

Modified: trunk/Source/WebCore/css/CSSFontPaletteValuesRule.cpp (283187 => 283188)


--- trunk/Source/WebCore/css/CSSFontPaletteValuesRule.cpp	2021-09-28 19:15:02 UTC (rev 283187)
+++ trunk/Source/WebCore/css/CSSFontPaletteValuesRule.cpp	2021-09-28 19:53:36 UTC (rev 283188)
@@ -58,7 +58,7 @@
 
 String CSSFontPaletteValuesRule::basePalette() const
 {
-    return WTF::switchOn(m_fontPaletteValuesRule->basePalette(), [&](int64_t index) {
+    return WTF::switchOn(m_fontPaletteValuesRule->basePalette(), [&](unsigned index) {
         return makeString(index);
     }, [&](const AtomString& basePalette) -> String {
         if (!basePalette.isNull())
@@ -70,9 +70,9 @@
 void CSSFontPaletteValuesRule::initializeMapLike(DOMMapAdapter& map)
 {
     for (auto& pair : m_fontPaletteValuesRule->overrideColors()) {
-        if (!WTF::holds_alternative<int64_t>(pair.first))
+        if (!WTF::holds_alternative<unsigned>(pair.first))
             continue;
-        map.set<IDLUnsignedLong, IDLUSVString>(WTF::get<int64_t>(pair.first), serializationForCSS(pair.second));
+        map.set<IDLUnsignedLong, IDLUSVString>(WTF::get<unsigned>(pair.first), serializationForCSS(pair.second));
     }
 }
 
@@ -82,7 +82,7 @@
     builder.append("@font-palette-values ", m_fontPaletteValuesRule->name(), " { ");
     if (!m_fontPaletteValuesRule->fontFamily().isNull())
         builder.append("font-family: ", m_fontPaletteValuesRule->fontFamily(), "; ");
-    WTF::switchOn(m_fontPaletteValuesRule->basePalette(), [&](int64_t index) {
+    WTF::switchOn(m_fontPaletteValuesRule->basePalette(), [&](unsigned index) {
         builder.append("base-palette: ", index, "; ");
     }, [&](const AtomString& basePalette) {
         if (!basePalette.isNull())
@@ -96,7 +96,7 @@
             builder.append(' ');
             WTF::switchOn(m_fontPaletteValuesRule->overrideColors()[i].first, [&](const AtomString& name) {
                 builder.append(serializeString(name.string()));
-            }, [&](int64_t index) {
+            }, [&](unsigned index) {
                 builder.append(index);
             });
             builder.append(' ', serializationForCSS(m_fontPaletteValuesRule->overrideColors()[i].second));

Modified: trunk/Source/WebCore/css/parser/CSSParserImpl.cpp (283187 => 283188)


--- trunk/Source/WebCore/css/parser/CSSParserImpl.cpp	2021-09-28 19:15:02 UTC (rev 283187)
+++ trunk/Source/WebCore/css/parser/CSSParserImpl.cpp	2021-09-28 19:53:36 UTC (rev 283188)
@@ -686,7 +686,7 @@
         if (primitiveValue.isString())
             basePalette = primitiveValue.stringValue();
         else if (primitiveValue.isNumber())
-            basePalette = primitiveValue.value<int64_t>();
+            basePalette = primitiveValue.value<unsigned>();
     }
 
     Vector<FontPaletteValues::OverriddenColor> overrideColors;
@@ -698,7 +698,7 @@
             if (pair.key().isString())
                 key = pair.key().stringValue();
             else if (pair.key().isNumber())
-                key = pair.key().value<int64_t>();
+                key = pair.key().value<unsigned>();
             else
                 continue;
             Color color = pair.color().isRGBColor() ? pair.color().color() : StyleColor::colorFromKeyword(pair.color().valueID(), { });

Modified: trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp (283187 => 283188)


--- trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp	2021-09-28 19:15:02 UTC (rev 283187)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp	2021-09-28 19:53:36 UTC (rev 283188)
@@ -4850,7 +4850,7 @@
 {
     if (range.peek().type() == StringToken)
         return consumeString(range);
-    return consumeInteger(range);
+    return consumeInteger(range, 0);
 }
 
 static RefPtr<CSSValueList> consumeOverrideColorsDescriptor(CSSParserTokenRange& range, const CSSParserContext& context)
@@ -4861,7 +4861,7 @@
         if (range.peek().type() == StringToken)
             key = consumeString(range);
         else
-            key = consumeInteger(range);
+            key = consumeInteger(range, 0);
         if (!key)
             return nullptr;
 

Modified: trunk/Source/WebCore/platform/graphics/FontPaletteValues.h (283187 => 283188)


--- trunk/Source/WebCore/platform/graphics/FontPaletteValues.h	2021-09-28 19:15:02 UTC (rev 283187)
+++ trunk/Source/WebCore/platform/graphics/FontPaletteValues.h	2021-09-28 19:53:36 UTC (rev 283188)
@@ -36,8 +36,8 @@
 
 class FontPaletteValues {
 public:
-    using PaletteIndex = Variant<int64_t, AtomString>;
-    using PaletteColorIndex = Variant<AtomString, int64_t>;
+    using PaletteIndex = Variant<unsigned, AtomString>;
+    using PaletteColorIndex = Variant<AtomString, unsigned>;
     using OverriddenColor = std::pair<PaletteColorIndex, Color>;
 
     FontPaletteValues() = default;

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp (283187 => 283188)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2021-09-28 19:15:02 UTC (rev 283187)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2021-09-28 19:53:36 UTC (rev 283188)
@@ -453,7 +453,7 @@
         break;
     case FontPalette::Type::Light: {
         auto light = kCTFontPaletteLight;
-        auto number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &light));
+        auto number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberCFIndexType, &light));
         CFDictionaryAddValue(attributes, kCTFontPaletteAttribute, number.get());
         break;
     }
@@ -464,12 +464,14 @@
         break;
     }
     case FontPalette::Type::Custom: {
-        WTF::switchOn(fontPaletteValues.basePalette(), [&](int64_t index) {
-            auto number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberCFIndexType, &index));
+        WTF::switchOn(fontPaletteValues.basePalette(), [&](unsigned index) {
+            int64_t rawIndex = index; // There is no kCFNumberUIntType.
+            auto number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &rawIndex));
             CFDictionaryAddValue(attributes, kCTFontPaletteAttribute, number.get());
         }, [](const AtomString&) {
             // This is unimplementable in Core Text.
         });
+
         if (!fontPaletteValues.overrideColors().isEmpty()) {
             auto overrideDictionary = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
             for (const auto& pair : fontPaletteValues.overrideColors()) {
@@ -477,8 +479,9 @@
                 const auto& color = pair.second;
                 WTF::switchOn(paletteColorIndex, [](const AtomString&) {
                     // This is unimplementable in Core Text.
-                }, [&](int64_t index) {
-                    auto number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &index));
+                }, [&](unsigned index) {
+                    int64_t rawIndex = index; // There is no kCFNumberUIntType.
+                    auto number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &rawIndex));
                     auto colorObject = cachedCGColor(color);
                     CFDictionaryAddValue(overrideDictionary.get(), number.get(), colorObject);
                 });
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to