⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 280587 in webkit


Ignore:
Timestamp:
Aug 3, 2021, 1:35:06 AM (5 years ago)
Author:
commit-queue@webkit.org
Message:

Crash in webgl/1.0.x/conformance/textures/misc/texture-with-flip-y-and-premultiply-alpha.html
https://bugs.webkit.org/show_bug.cgi?id=223920
<rdar://problem/76261913>

Patch by Kimmo Kinnunen <kkinnunen@apple.com> on 2021-08-03
Reviewed by Kenneth Russell.

After enabling WEBGL_depth_texture, the getDataFormat would assert for case of
format == RGBA, type == UNSIGNED_SHORT. UNSIGNED_SHORT is intended for
format == DEPTH_COMPONENT.

Instead, return error if the data conversion cannot be done. This is better in all
cases than doing non-expected data conversion in release build and assertion in
debug builds.

Tested by webgl/1.0.x/conformance/textures/misc/texture-with-flip-y-and-premultiply-alpha.html
(disabled for now).

  • html/canvas/WebGLRenderingContextBase.cpp:

(WebCore::WebGLRenderingContextBase::texImageArrayBufferViewHelper):

  • platform/graphics/GraphicsContextGL.cpp:

(WebCore::getDataFormat):
(WebCore::packPixels):
(WebCore::GraphicsContextGL::extractTextureData):

  • platform/graphics/GraphicsContextGL.h:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r280586 r280587  
     12021-08-03  Kimmo Kinnunen  <kkinnunen@apple.com>
     2
     3        Crash in webgl/1.0.x/conformance/textures/misc/texture-with-flip-y-and-premultiply-alpha.html
     4        https://bugs.webkit.org/show_bug.cgi?id=223920
     5        <rdar://problem/76261913>
     6
     7        Reviewed by Kenneth Russell.
     8
     9        After enabling WEBGL_depth_texture, the getDataFormat would assert for case of
     10        format == RGBA, type == UNSIGNED_SHORT. UNSIGNED_SHORT is intended for
     11        format == DEPTH_COMPONENT.
     12
     13        Instead, return error if the data conversion cannot be done. This is better in all
     14        cases than doing non-expected data conversion in release build and assertion in
     15        debug builds.
     16
     17        Tested by webgl/1.0.x/conformance/textures/misc/texture-with-flip-y-and-premultiply-alpha.html
     18        (disabled for now).
     19
     20        * html/canvas/WebGLRenderingContextBase.cpp:
     21        (WebCore::WebGLRenderingContextBase::texImageArrayBufferViewHelper):
     22        * platform/graphics/GraphicsContextGL.cpp:
     23        (WebCore::getDataFormat):
     24        (WebCore::packPixels):
     25        (WebCore::GraphicsContextGL::extractTextureData):
     26        * platform/graphics/GraphicsContextGL.h:
     27
    1282021-08-03  Rob Buis  <rbuis@igalia.com>
    229
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp

    r279793 r280587  
    49904990            return;
    49914991        }
    4992         if (!m_context->extractTextureData(width, height, format, type, unpackParams, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempData))
     4992        if (!m_context->extractTextureData(width, height, format, type, unpackParams, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempData)) {
     4993            synthesizeGLError(GraphicsContextGL::INVALID_OPERATION, functionName, "Invalid format/type combination.");
    49934994            return;
     4995        }
    49944996        data = tempData.data();
    49954997        byteLength = tempData.size();
  • trunk/Source/WebCore/platform/graphics/GraphicsContextGL.cpp

    r278619 r280587  
    4343static GraphicsContextGL::DataFormat getDataFormat(GCGLenum destinationFormat, GCGLenum destinationType)
    4444{
    45     GraphicsContextGL::DataFormat dstFormat = GraphicsContextGL::DataFormat::RGBA8;
    4645    switch (destinationType) {
    4746    case GraphicsContextGL::BYTE:
     
    4948        case GraphicsContextGL::RED:
    5049        case GraphicsContextGL::RED_INTEGER:
    51             dstFormat = GraphicsContextGL::DataFormat::R8_S;
    52             break;
     50            return GraphicsContextGL::DataFormat::R8_S;
    5351        case GraphicsContextGL::RG:
    5452        case GraphicsContextGL::RG_INTEGER:
    55             dstFormat = GraphicsContextGL::DataFormat::RG8_S;
    56             break;
     53            return GraphicsContextGL::DataFormat::RG8_S;
    5754        case GraphicsContextGL::RGB:
    5855        case GraphicsContextGL::RGB_INTEGER:
    59             dstFormat = GraphicsContextGL::DataFormat::RGB8_S;
    60             break;
     56            return GraphicsContextGL::DataFormat::RGB8_S;
    6157        case GraphicsContextGL::RGBA:
    6258        case GraphicsContextGL::RGBA_INTEGER:
    63             dstFormat = GraphicsContextGL::DataFormat::RGBA8_S;
    64             break;
     59            return GraphicsContextGL::DataFormat::RGBA8_S;
    6560        default:
    66             ASSERT_NOT_REACHED();
    67         }
    68         break;
     61            return GraphicsContextGL::DataFormat::Invalid;
     62        }
    6963    case GraphicsContextGL::UNSIGNED_BYTE:
    7064        switch (destinationFormat) {
     
    7266        case GraphicsContextGL::RGB_INTEGER:
    7367        case GraphicsContextGL::SRGB:
    74             dstFormat = GraphicsContextGL::GraphicsContextGL::DataFormat::RGB8;
    75             break;
     68            return GraphicsContextGL::GraphicsContextGL::DataFormat::RGB8;
    7669        case GraphicsContextGL::RGBA:
    7770        case GraphicsContextGL::RGBA_INTEGER:
    7871        case GraphicsContextGL::SRGB_ALPHA:
    79             dstFormat = GraphicsContextGL::DataFormat::RGBA8;
    80             break;
     72            return GraphicsContextGL::DataFormat::RGBA8;
    8173        case GraphicsContextGL::ALPHA:
    82             dstFormat = GraphicsContextGL::DataFormat::A8;
    83             break;
     74            return GraphicsContextGL::DataFormat::A8;
    8475        case GraphicsContextGL::LUMINANCE:
    8576        case GraphicsContextGL::RED:
    8677        case GraphicsContextGL::RED_INTEGER:
    87             dstFormat = GraphicsContextGL::DataFormat::R8;
    88             break;
     78            return GraphicsContextGL::DataFormat::R8;
    8979        case GraphicsContextGL::RG:
    9080        case GraphicsContextGL::RG_INTEGER:
    91             dstFormat = GraphicsContextGL::DataFormat::RG8;
    92             break;
     81            return GraphicsContextGL::DataFormat::RG8;
    9382        case GraphicsContextGL::LUMINANCE_ALPHA:
    94             dstFormat = GraphicsContextGL::DataFormat::RA8;
    95             break;
     83            return GraphicsContextGL::DataFormat::RA8;
    9684        default:
    97             ASSERT_NOT_REACHED();
    98         }
    99         break;
     85            return GraphicsContextGL::DataFormat::Invalid;
     86        }
    10087    case GraphicsContextGL::SHORT:
    10188        switch (destinationFormat) {
    10289        case GraphicsContextGL::RED_INTEGER:
    103             dstFormat = GraphicsContextGL::DataFormat::R16_S;
    104             break;
     90            return GraphicsContextGL::DataFormat::R16_S;
    10591        case GraphicsContextGL::RG_INTEGER:
    106             dstFormat = GraphicsContextGL::DataFormat::RG16_S;
    107             break;
     92            return GraphicsContextGL::DataFormat::RG16_S;
    10893        case GraphicsContextGL::RGB_INTEGER:
    109             dstFormat = GraphicsContextGL::DataFormat::RGB16_S;
    110             break;
     94            return GraphicsContextGL::DataFormat::RGB16_S;
    11195        case GraphicsContextGL::RGBA_INTEGER:
    112             dstFormat = GraphicsContextGL::DataFormat::RGBA16_S;
    113             break;
     96            return GraphicsContextGL::DataFormat::RGBA16_S;
    11497        default:
    115             ASSERT_NOT_REACHED();
    116         }
    117         break;
     98            return GraphicsContextGL::DataFormat::Invalid;
     99        }
    118100    case GraphicsContextGL::UNSIGNED_SHORT:
    119101        switch (destinationFormat) {
    120102        case GraphicsContextGL::RED_INTEGER:
    121             dstFormat = GraphicsContextGL::DataFormat::R16;
    122             break;
     103            return GraphicsContextGL::DataFormat::R16;
    123104        case GraphicsContextGL::DEPTH_COMPONENT:
    124             dstFormat = GraphicsContextGL::DataFormat::D16;
    125             break;
     105            return GraphicsContextGL::DataFormat::D16;
    126106        case GraphicsContextGL::RG_INTEGER:
    127             dstFormat = GraphicsContextGL::DataFormat::RG16;
    128             break;
     107            return GraphicsContextGL::DataFormat::RG16;
    129108        case GraphicsContextGL::RGB_INTEGER:
    130             dstFormat = GraphicsContextGL::DataFormat::RGB16;
    131             break;
     109            return GraphicsContextGL::DataFormat::RGB16;
    132110        case GraphicsContextGL::RGBA_INTEGER:
    133             dstFormat = GraphicsContextGL::DataFormat::RGBA16;
    134             break;
     111            return GraphicsContextGL::DataFormat::RGBA16;
    135112        default:
    136             ASSERT_NOT_REACHED();
    137         }
    138         break;
     113            return GraphicsContextGL::DataFormat::Invalid;
     114        }
    139115    case GraphicsContextGL::INT:
    140116        switch (destinationFormat) {
    141117        case GraphicsContextGL::RED_INTEGER:
    142             dstFormat = GraphicsContextGL::DataFormat::R32_S;
    143             break;
     118            return GraphicsContextGL::DataFormat::R32_S;
    144119        case GraphicsContextGL::RG_INTEGER:
    145             dstFormat = GraphicsContextGL::DataFormat::RG32_S;
    146             break;
     120            return GraphicsContextGL::DataFormat::RG32_S;
    147121        case GraphicsContextGL::RGB_INTEGER:
    148             dstFormat = GraphicsContextGL::DataFormat::RGB32_S;
    149             break;
     122            return GraphicsContextGL::DataFormat::RGB32_S;
    150123        case GraphicsContextGL::RGBA_INTEGER:
    151             dstFormat = GraphicsContextGL::DataFormat::RGBA32_S;
    152             break;
     124            return GraphicsContextGL::DataFormat::RGBA32_S;
    153125        default:
    154             ASSERT_NOT_REACHED();
    155         }
    156         break;
     126            return GraphicsContextGL::DataFormat::Invalid;
     127        }
    157128    case GraphicsContextGL::UNSIGNED_INT:
    158129        switch (destinationFormat) {
    159130        case GraphicsContextGL::RED_INTEGER:
    160             dstFormat = GraphicsContextGL::DataFormat::R32;
    161             break;
     131            return GraphicsContextGL::DataFormat::R32;
    162132        case GraphicsContextGL::DEPTH_COMPONENT:
    163             dstFormat = GraphicsContextGL::DataFormat::D32;
    164             break;
     133            return GraphicsContextGL::DataFormat::D32;
    165134        case GraphicsContextGL::RG_INTEGER:
    166             dstFormat = GraphicsContextGL::DataFormat::RG32;
    167             break;
     135            return GraphicsContextGL::DataFormat::RG32;
    168136        case GraphicsContextGL::RGB_INTEGER:
    169             dstFormat = GraphicsContextGL::DataFormat::RGB32;
    170             break;
     137            return GraphicsContextGL::DataFormat::RGB32;
    171138        case GraphicsContextGL::RGBA_INTEGER:
    172             dstFormat = GraphicsContextGL::DataFormat::RGBA32;
    173             break;
     139            return GraphicsContextGL::DataFormat::RGBA32;
    174140        default:
    175             ASSERT_NOT_REACHED();
    176         }
    177         break;
     141            return GraphicsContextGL::DataFormat::Invalid;
     142        }
    178143    case GraphicsContextGL::HALF_FLOAT_OES: // OES_texture_half_float
    179144    case GraphicsContextGL::HALF_FLOAT:
    180145        switch (destinationFormat) {
    181146        case GraphicsContextGL::RGBA:
    182             dstFormat = GraphicsContextGL::DataFormat::RGBA16F;
    183             break;
     147            return GraphicsContextGL::DataFormat::RGBA16F;
    184148        case GraphicsContextGL::RGB:
    185             dstFormat = GraphicsContextGL::DataFormat::RGB16F;
    186             break;
     149            return GraphicsContextGL::DataFormat::RGB16F;
    187150        case GraphicsContextGL::RG:
    188             dstFormat = GraphicsContextGL::DataFormat::RG16F;
    189             break;
     151            return GraphicsContextGL::DataFormat::RG16F;
    190152        case GraphicsContextGL::ALPHA:
    191             dstFormat = GraphicsContextGL::DataFormat::A16F;
    192             break;
     153            return GraphicsContextGL::DataFormat::A16F;
    193154        case GraphicsContextGL::LUMINANCE:
    194155        case GraphicsContextGL::RED:
    195             dstFormat = GraphicsContextGL::DataFormat::R16F;
    196             break;
     156            return GraphicsContextGL::DataFormat::R16F;
    197157        case GraphicsContextGL::LUMINANCE_ALPHA:
    198             dstFormat = GraphicsContextGL::DataFormat::RA16F;
    199             break;
     158            return GraphicsContextGL::DataFormat::RA16F;
    200159        case GraphicsContextGL::SRGB:
    201             dstFormat = GraphicsContextGL::DataFormat::RGB16F;
    202             break;
     160            return GraphicsContextGL::DataFormat::RGB16F;
    203161        case GraphicsContextGL::SRGB_ALPHA:
    204             dstFormat = GraphicsContextGL::DataFormat::RGBA16F;
    205             break;
     162            return GraphicsContextGL::DataFormat::RGBA16F;
    206163        default:
    207             ASSERT_NOT_REACHED();
    208         }
    209         break;
     164            return GraphicsContextGL::DataFormat::Invalid;
     165        }
    210166    case GraphicsContextGL::FLOAT: // OES_texture_float
    211167        switch (destinationFormat) {
    212168        case GraphicsContextGL::RGBA:
    213             dstFormat = GraphicsContextGL::DataFormat::RGBA32F;
    214             break;
     169            return GraphicsContextGL::DataFormat::RGBA32F;
    215170        case GraphicsContextGL::RGB:
    216             dstFormat = GraphicsContextGL::DataFormat::RGB32F;
    217             break;
     171            return GraphicsContextGL::DataFormat::RGB32F;
    218172        case GraphicsContextGL::RG:
    219             dstFormat = GraphicsContextGL::DataFormat::RG32F;
    220             break;
     173            return GraphicsContextGL::DataFormat::RG32F;
    221174        case GraphicsContextGL::ALPHA:
    222             dstFormat = GraphicsContextGL::DataFormat::A32F;
    223             break;
     175            return GraphicsContextGL::DataFormat::A32F;
    224176        case GraphicsContextGL::LUMINANCE:
    225177        case GraphicsContextGL::RED:
    226             dstFormat = GraphicsContextGL::DataFormat::R32F;
    227             break;
     178            return GraphicsContextGL::DataFormat::R32F;
    228179        case GraphicsContextGL::DEPTH_COMPONENT:
    229             dstFormat = GraphicsContextGL::DataFormat::D32F;
    230             break;
     180            return GraphicsContextGL::DataFormat::D32F;
    231181        case GraphicsContextGL::LUMINANCE_ALPHA:
    232             dstFormat = GraphicsContextGL::DataFormat::RA32F;
    233             break;
     182            return GraphicsContextGL::DataFormat::RA32F;
    234183        case GraphicsContextGL::SRGB:
    235             dstFormat = GraphicsContextGL::DataFormat::RGB32F;
    236             break;
     184            return GraphicsContextGL::DataFormat::RGB32F;
    237185        case GraphicsContextGL::SRGB_ALPHA:
    238             dstFormat = GraphicsContextGL::DataFormat::RGBA32F;
    239             break;
     186            return GraphicsContextGL::DataFormat::RGBA32F;
    240187        default:
    241             ASSERT_NOT_REACHED();
    242         }
    243         break;
     188            return GraphicsContextGL::DataFormat::Invalid;
     189        }
    244190    case GraphicsContextGL::UNSIGNED_SHORT_4_4_4_4:
    245         dstFormat = GraphicsContextGL::DataFormat::RGBA4444;
    246         break;
     191        return GraphicsContextGL::DataFormat::RGBA4444;
    247192    case GraphicsContextGL::UNSIGNED_SHORT_5_5_5_1:
    248         dstFormat = GraphicsContextGL::DataFormat::RGBA5551;
    249         break;
     193        return GraphicsContextGL::DataFormat::RGBA5551;
    250194    case GraphicsContextGL::UNSIGNED_SHORT_5_6_5:
    251         dstFormat = GraphicsContextGL::DataFormat::RGB565;
    252         break;
     195        return GraphicsContextGL::DataFormat::RGB565;
    253196    case GraphicsContextGL::UNSIGNED_INT_5_9_9_9_REV:
    254         dstFormat = GraphicsContextGL::DataFormat::RGB5999;
    255         break;
     197        return GraphicsContextGL::DataFormat::RGB5999;
    256198    case GraphicsContextGL::UNSIGNED_INT_24_8:
    257         dstFormat = GraphicsContextGL::DataFormat::DS24_8;
    258         break;
     199        return GraphicsContextGL::DataFormat::DS24_8;
    259200    case GraphicsContextGL::UNSIGNED_INT_10F_11F_11F_REV:
    260         dstFormat = GraphicsContextGL::DataFormat::RGB10F11F11F;
    261         break;
     201        return GraphicsContextGL::DataFormat::RGB10F11F11F;
    262202    case GraphicsContextGL::UNSIGNED_INT_2_10_10_10_REV:
    263         dstFormat = GraphicsContextGL::DataFormat::RGBA2_10_10_10;
    264         break;
     203        return GraphicsContextGL::DataFormat::RGBA2_10_10_10;
    265204    default:
    266         ASSERT_NOT_REACHED();
    267     }
    268     return dstFormat;
     205        return GraphicsContextGL::DataFormat::Invalid;
     206    }
     207    ASSERT_NOT_REACHED();
     208    return GraphicsContextGL::DataFormat::Invalid;
    269209}
    270210
     
    356296
    357297    GraphicsContextGL::DataFormat dstDataFormat = getDataFormat(destinationFormat, destinationType);
     298    if (dstDataFormat == GraphicsContextGL::DataFormat::Invalid)
     299        return false;
    358300    int dstStride = sourceDataSubRectangle.width() * texelBytesForFormat(dstDataFormat);
    359301    if (flipY) {
     
    788730    // Assumes format, type, etc. have already been validated.
    789731    DataFormat sourceDataFormat = getDataFormat(format, type);
    790 
     732    if (sourceDataFormat == GraphicsContextGL::DataFormat::Invalid)
     733        return false;
    791734    // Resize the output buffer.
    792735    unsigned componentsPerPixel, bytesPerComponent;
  • trunk/Source/WebCore/platform/graphics/GraphicsContextGL.h

    r278253 r280587  
    749749        D32F,
    750750        DS24_8,
    751         NumFormats
     751        NumFormats,
     752        Invalid = NumFormats
    752753    };
    753754
Note: See TracChangeset for help on using the changeset viewer.