Changeset 228066 in webkit


Ignore:
Timestamp:
Feb 4, 2018 6:19:11 PM (6 years ago)
Author:
jmarcell@apple.com
Message:

Cherry-pick r227994. rdar://problem/37145542

Location:
branches/safari-605-branch
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-605-branch/JSTests/ChangeLog

    r227922 r228066  
     12018-02-04  Jason Marcell  <jmarcell@apple.com>
     2
     3        Cherry-pick r227994. rdar://problem/37145542
     4
     5    2018-02-01  Keith Miller  <keith_miller@apple.com>
     6
     7            Fix crashes due to mishandling custom sections.
     8            https://bugs.webkit.org/show_bug.cgi?id=182404
     9            <rdar://problem/36935863>
     10
     11            Reviewed by Saam Barati.
     12
     13            * wasm/Builder.js:
     14            (export.default.Builder.prototype._registerSectionBuilders.const.section.in.WASM.description.section.switch.section.case.string_appeared_here.this.section):
     15            * wasm/js-api/validate.js:
     16            (assert.truthy):
     17
    1182018-01-31  Jason Marcell  <jmarcell@apple.com>
    219
  • branches/safari-605-branch/JSTests/wasm/Builder.js

    r216598 r228066  
    576576            case "Element":
    577577                this[section] = function(...args) {
    578                     if (args.length !== 0)
     578                    if (args.length !== 0 && this._checked)
    579579                        throw new Error("You're doing it wrong. This element does not take arguments. You must chain the call with another Element()");
    580580
  • branches/safari-605-branch/JSTests/wasm/js-api/validate.js

    r214601 r228066  
    3030    assert.truthy(WebAssembly.validate(builder.WebAssembly().get()));
    3131}
     32
     33{
     34    const builder = (new Builder());
     35    builder.setChecked(false);
     36
     37    builder.Type().End()
     38        .Import().Memory("imp", "memory", {initial: 20}).End()
     39        .Unknown("test").End()
     40        .Import().Memory("imp", "memory", {initial: 20}).End()
     41        .Function().End()
     42        .Export().End()
     43        .Code()
     44        .End();
     45
     46    assert.falsy(WebAssembly.validate(builder.WebAssembly().get()));
     47}
  • branches/safari-605-branch/Source/JavaScriptCore/ChangeLog

    r228060 r228066  
     12018-02-04  Jason Marcell  <jmarcell@apple.com>
     2
     3        Cherry-pick r227994. rdar://problem/37145542
     4
     5    2018-02-01  Keith Miller  <keith_miller@apple.com>
     6
     7            Fix crashes due to mishandling custom sections.
     8            https://bugs.webkit.org/show_bug.cgi?id=182404
     9            <rdar://problem/36935863>
     10
     11            Reviewed by Saam Barati.
     12
     13            This also cleans up some of our validation code. We also
     14            mistakenly, allowed unknown (different from custom sections with
     15            id: 0) section ids.
     16
     17            * wasm/WasmModuleParser.cpp:
     18            (JSC::Wasm::ModuleParser::parse):
     19            * wasm/WasmModuleParser.h:
     20            * wasm/WasmSections.h:
     21            (JSC::Wasm::isKnownSection):
     22            (JSC::Wasm::decodeSection):
     23            (JSC::Wasm::validateOrder):
     24            (JSC::Wasm::makeString):
     25            (JSC::Wasm::isValidSection): Deleted.
     26
    1272018-02-04  Jason Marcell  <jmarcell@apple.com>
    228
  • branches/safari-605-branch/Source/JavaScriptCore/wasm/WasmModuleParser.cpp

    r225499 r228066  
    5656    WASM_PARSER_FAIL_IF(versionNumber != expectedVersionNumber, "unexpected version number ", versionNumber, " expected ", expectedVersionNumber);
    5757
    58     Section previousSection = Section::Custom;
     58    // This is not really a known section.
     59    Section previousKnownSection = Section::Begin;
    5960    while (m_offset < length()) {
    6061        uint8_t sectionByte;
     
    6364
    6465        Section section = Section::Custom;
    65         if (sectionByte) {
    66             if (isValidSection(sectionByte))
    67                 section = static_cast<Section>(sectionByte);
    68         }
     66        WASM_PARSER_FAIL_IF(!decodeSection(sectionByte, section));
     67        ASSERT(section != Section::Begin);
    6968
    7069        uint32_t sectionLength;
    71         WASM_PARSER_FAIL_IF(!validateOrder(previousSection, section), "invalid section order, ", previousSection, " followed by ", section);
     70        WASM_PARSER_FAIL_IF(!validateOrder(previousKnownSection, section), "invalid section order, ", previousKnownSection, " followed by ", section);
    7271        WASM_PARSER_FAIL_IF(!parseVarUInt32(sectionLength), "can't get ", section, " section's length");
    7372        WASM_PARSER_FAIL_IF(sectionLength > length() - m_offset, section, "section of size ", sectionLength, " would overflow Module's size");
     
    8180            break;                                                  \
    8281        }
    83         FOR_EACH_WASM_SECTION(WASM_SECTION_PARSE)
     82        FOR_EACH_KNOWN_WASM_SECTION(WASM_SECTION_PARSE)
    8483#undef WASM_SECTION_PARSE
    8584
     
    8887            break;
    8988        }
     89
     90        case Section::Begin: {
     91            RELEASE_ASSERT_NOT_REACHED();
     92            break;
     93        }
    9094        }
    9195
    9296        WASM_PARSER_FAIL_IF(end != m_offset, "parsing ended before the end of ", section, " section");
    9397
    94         previousSection = section;
     98
     99        if (isKnownSection(section))
     100            previousKnownSection = section;
    95101    }
    96102
  • branches/safari-605-branch/Source/JavaScriptCore/wasm/WasmModuleParser.h

    r218216 r228066  
    4949
    5050#define WASM_SECTION_DECLARE_PARSER(NAME, ID, DESCRIPTION) PartialResult WARN_UNUSED_RETURN parse ## NAME();
    51     FOR_EACH_WASM_SECTION(WASM_SECTION_DECLARE_PARSER)
     51    FOR_EACH_KNOWN_WASM_SECTION(WASM_SECTION_DECLARE_PARSER)
    5252#undef WASM_SECTION_DECLARE_PARSER
    5353
  • branches/safari-605-branch/Source/JavaScriptCore/wasm/WasmSections.h

    r214942 r228066  
    3535namespace JSC { namespace Wasm {
    3636
    37 #define FOR_EACH_WASM_SECTION(macro) \
     37#define FOR_EACH_KNOWN_WASM_SECTION(macro) \
    3838    macro(Type,     1, "Function signature declarations") \
    3939    macro(Import,   2, "Import declarations") \
     
    4949
    5050enum class Section : uint8_t {
     51    // It's important that Begin is less than every other section number and that Custom is greater.
     52    // This only works because section numbers are currently monotonically increasing.
     53    // Also, Begin is not a real section but is used as a marker for validating the ordering
     54    // of sections.
     55    Begin = 0,
    5156#define DEFINE_WASM_SECTION_ENUM(NAME, ID, DESCRIPTION) NAME = ID,
    52     FOR_EACH_WASM_SECTION(DEFINE_WASM_SECTION_ENUM)
     57    FOR_EACH_KNOWN_WASM_SECTION(DEFINE_WASM_SECTION_ENUM)
    5358#undef DEFINE_WASM_SECTION_ENUM
    5459    Custom
    5560};
     61static_assert(static_cast<uint8_t>(Section::Begin) < static_cast<uint8_t>(Section::Type), "Begin should come before the first known section.");
    5662
    5763template<typename Int>
    58 static inline bool isValidSection(Int section)
     64inline bool isKnownSection(Int section)
    5965{
    6066    switch (section) {
    6167#define VALIDATE_SECTION(NAME, ID, DESCRIPTION) case static_cast<Int>(Section::NAME): return true;
    62         FOR_EACH_WASM_SECTION(VALIDATE_SECTION)
     68        FOR_EACH_KNOWN_WASM_SECTION(VALIDATE_SECTION)
    6369#undef VALIDATE_SECTION
    6470    default:
     
    6773}
    6874
    69 static inline bool validateOrder(Section previous, Section next)
     75inline bool decodeSection(uint8_t sectionByte, Section& section)
    7076{
    71     if (previous == Section::Custom)
     77    section = Section::Custom;
     78    if (!sectionByte)
    7279        return true;
    73     return static_cast<uint8_t>(previous) < static_cast<uint8_t>(next);
     80
     81    if (!isKnownSection(sectionByte))
     82        return false;
     83
     84    section = static_cast<Section>(sectionByte);
     85    return true;
    7486}
    7587
    76 static inline const char* makeString(Section section)
     88inline bool validateOrder(Section previousKnown, Section next)
     89{
     90    ASSERT(isKnownSection(previousKnown) || previousKnown == Section::Begin);
     91    return static_cast<uint8_t>(previousKnown) < static_cast<uint8_t>(next);
     92}
     93
     94inline const char* makeString(Section section)
    7795{
    7896    switch (section) {
     97    case Section::Begin:
     98        return "Begin";
    7999    case Section::Custom:
    80100        return "Custom";
    81101#define STRINGIFY_SECTION_NAME(NAME, ID, DESCRIPTION) case Section::NAME: return #NAME;
    82         FOR_EACH_WASM_SECTION(STRINGIFY_SECTION_NAME)
     102        FOR_EACH_KNOWN_WASM_SECTION(STRINGIFY_SECTION_NAME)
    83103#undef STRINGIFY_SECTION_NAME
    84104    }
Note: See TracChangeset for help on using the changeset viewer.