LCOV - code coverage report
Current view: top level - test/unittests/wasm - streaming-decoder-unittest.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 187 190 98.4 %
Date: 2019-01-20 Functions: 79 116 68.1 %

          Line data    Source code
       1             : // Copyright 2017 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "test/unittests/test-utils.h"
       6             : 
       7             : #include "src/objects-inl.h"
       8             : 
       9             : #include "src/wasm/module-decoder.h"
      10             : #include "src/wasm/streaming-decoder.h"
      11             : 
      12             : #include "src/objects/descriptor-array.h"
      13             : #include "src/objects/dictionary.h"
      14             : #include "test/common/wasm/wasm-macro-gen.h"
      15             : 
      16             : namespace v8 {
      17             : namespace internal {
      18             : namespace wasm {
      19             : 
      20             : struct MockStreamingResult {
      21             :   size_t num_sections = 0;
      22             :   size_t num_functions = 0;
      23             :   bool ok = true;
      24             :   OwnedVector<uint8_t> received_bytes;
      25             : 
      26             :   MockStreamingResult() = default;
      27             : };
      28             : 
      29        2272 : class MockStreamingProcessor : public StreamingProcessor {
      30             :  public:
      31             :   explicit MockStreamingProcessor(MockStreamingResult* result)
      32        1136 :       : result_(result) {}
      33             : 
      34        1099 :   bool ProcessModuleHeader(Vector<const uint8_t> bytes,
      35             :                            uint32_t offset) override {
      36             :     // TODO(ahaas): Share code with the module-decoder.
      37             :     Decoder decoder(bytes.begin(), bytes.end());
      38             :     uint32_t magic_word = decoder.consume_u32("wasm magic");
      39        1099 :     if (decoder.failed() || magic_word != kWasmMagic) {
      40         288 :       result_->ok = false;
      41         288 :       return false;
      42             :     }
      43             :     uint32_t magic_version = decoder.consume_u32("wasm version");
      44         811 :     if (decoder.failed() || magic_version != kWasmVersion) {
      45         288 :       result_->ok = false;
      46         288 :       return false;
      47             :     }
      48             :     return true;
      49             :   }
      50             :   // Process all sections but the code section.
      51         269 :   bool ProcessSection(SectionCode section_code, Vector<const uint8_t> bytes,
      52             :                       uint32_t offset) override {
      53         269 :     ++result_->num_sections;
      54         269 :     return true;
      55             :   }
      56             : 
      57         274 :   bool ProcessCodeSectionHeader(size_t num_functions, uint32_t offset,
      58             :                                 std::shared_ptr<WireBytesStorage>) override {
      59         274 :     return true;
      60             :   }
      61             : 
      62             :   // Process a function body.
      63         353 :   bool ProcessFunctionBody(Vector<const uint8_t> bytes,
      64             :                            uint32_t offset) override {
      65         353 :     ++result_->num_functions;
      66         353 :     return true;
      67             :   }
      68             : 
      69        1371 :   void OnFinishedChunk() override {}
      70             : 
      71             :   // Finish the processing of the stream.
      72         260 :   void OnFinishedStream(OwnedVector<uint8_t> bytes) override {
      73         260 :     result_->received_bytes = std::move(bytes);
      74         260 :   }
      75             : 
      76             :   // Report an error detected in the StreamingDecoder.
      77         300 :   void OnError(const WasmError&) override { result_->ok = false; }
      78             : 
      79           0 :   void OnAbort() override {}
      80             : 
      81           0 :   bool Deserialize(Vector<const uint8_t> module_bytes,
      82             :                    Vector<const uint8_t> wire_bytes) override {
      83           0 :     return false;
      84             :   };
      85             : 
      86             :  private:
      87             :   MockStreamingResult* const result_;
      88             : };
      89             : 
      90          99 : class WasmStreamingDecoderTest : public ::testing::Test {
      91             :  public:
      92          15 :   void ExpectVerifies(Vector<const uint8_t> data, size_t expected_sections,
      93             :                       size_t expected_functions) {
      94         550 :     for (int split = 0; split <= data.length(); ++split) {
      95         260 :       MockStreamingResult result;
      96             :       StreamingDecoder stream(
      97         780 :           base::make_unique<MockStreamingProcessor>(&result));
      98         520 :       stream.OnBytesReceived(data.SubVector(0, split));
      99         780 :       stream.OnBytesReceived(data.SubVector(split, data.length()));
     100         260 :       stream.Finish();
     101         260 :       EXPECT_TRUE(result.ok);
     102         260 :       EXPECT_EQ(expected_sections, result.num_sections);
     103         260 :       EXPECT_EQ(expected_functions, result.num_functions);
     104         520 :       EXPECT_EQ(data, result.received_bytes.as_vector());
     105             :     }
     106          15 :   }
     107             : 
     108          85 :   void ExpectFailure(Vector<const uint8_t> data) {
     109        1918 :     for (int split = 0; split <= data.length(); ++split) {
     110         874 :       MockStreamingResult result;
     111             :       StreamingDecoder stream(
     112        2622 :           base::make_unique<MockStreamingProcessor>(&result));
     113         874 :       stream.OnBytesReceived(data.SubVector(0, split));
     114        1748 :       stream.OnBytesReceived(data.SubVector(split, data.length()));
     115         874 :       stream.Finish();
     116        1748 :       EXPECT_FALSE(result.ok);
     117             :     }
     118          85 :   }
     119             : 
     120             :   MockStreamingResult result;
     121             : };
     122             : 
     123       15128 : TEST_F(WasmStreamingDecoderTest, EmptyStream) {
     124           1 :   MockStreamingResult result;
     125           3 :   StreamingDecoder stream(base::make_unique<MockStreamingProcessor>(&result));
     126           1 :   stream.Finish();
     127           2 :   EXPECT_FALSE(result.ok);
     128           1 : }
     129             : 
     130       15128 : TEST_F(WasmStreamingDecoderTest, IncompleteModuleHeader) {
     131           1 :   const uint8_t data[] = {U32_LE(kWasmMagic), U32_LE(kWasmVersion)};
     132             :   {
     133           1 :     MockStreamingResult result;
     134           3 :     StreamingDecoder stream(base::make_unique<MockStreamingProcessor>(&result));
     135           1 :     stream.OnBytesReceived(Vector<const uint8_t>(data, 1));
     136           1 :     stream.Finish();
     137           2 :     EXPECT_FALSE(result.ok);
     138             :   }
     139           8 :   for (int length = 1; length < static_cast<int>(arraysize(data)); ++length) {
     140          14 :     ExpectFailure(Vector<const uint8_t>(data, length));
     141             :   }
     142           1 : }
     143             : 
     144       15128 : TEST_F(WasmStreamingDecoderTest, MagicAndVersion) {
     145           1 :   const uint8_t data[] = {U32_LE(kWasmMagic), U32_LE(kWasmVersion)};
     146           1 :   ExpectVerifies(ArrayVector(data), 0, 0);
     147           1 : }
     148             : 
     149       15128 : TEST_F(WasmStreamingDecoderTest, BadMagic) {
     150          33 :   for (uint32_t x = 1; x; x <<= 1) {
     151          32 :     const uint8_t data[] = {U32_LE(kWasmMagic ^ x), U32_LE(kWasmVersion)};
     152          32 :     ExpectFailure(ArrayVector(data));
     153             :   }
     154           1 : }
     155             : 
     156       15128 : TEST_F(WasmStreamingDecoderTest, BadVersion) {
     157          33 :   for (uint32_t x = 1; x; x <<= 1) {
     158          32 :     const uint8_t data[] = {U32_LE(kWasmMagic), U32_LE(kWasmVersion ^ x)};
     159          32 :     ExpectFailure(ArrayVector(data));
     160             :   }
     161           1 : }
     162             : 
     163       15128 : TEST_F(WasmStreamingDecoderTest, OneSection) {
     164             :   const uint8_t data[] = {
     165             :       U32_LE(kWasmMagic),    // --
     166             :       U32_LE(kWasmVersion),  // --
     167             :       0x1,                   // Section ID
     168             :       0x6,                   // Section Length
     169             :       0x0,                   // Payload
     170             :       0x0,                   // 2
     171             :       0x0,                   // 3
     172             :       0x0,                   // 4
     173             :       0x0,                   // 5
     174             :       0x0                    // 6
     175           1 :   };
     176           1 :   ExpectVerifies(ArrayVector(data), 1, 0);
     177           1 : }
     178             : 
     179       15128 : TEST_F(WasmStreamingDecoderTest, OneSection_b) {
     180             :   const uint8_t data[] = {
     181             :       U32_LE(kWasmMagic),    // --
     182             :       U32_LE(kWasmVersion),  // --
     183             :       0x1,                   // Section ID
     184             :       0x86,                  // Section Length = 6 (LEB)
     185             :       0x0,                   // --
     186             :       0x0,                   // Payload
     187             :       0x0,                   // 2
     188             :       0x0,                   // 3
     189             :       0x0,                   // 4
     190             :       0x0,                   // 5
     191             :       0x0                    // 6
     192           1 :   };
     193           1 :   ExpectVerifies(ArrayVector(data), 1, 0);
     194           1 : }
     195             : 
     196       15128 : TEST_F(WasmStreamingDecoderTest, OneShortSection) {
     197             :   // Short section means that section length + payload is less than 5 bytes,
     198             :   // which is the maximum size of the length field.
     199             :   const uint8_t data[] = {
     200             :       U32_LE(kWasmMagic),    // --
     201             :       U32_LE(kWasmVersion),  // --
     202             :       0x1,                   // Section ID
     203             :       0x2,                   // Section Length
     204             :       0x0,                   // Payload
     205             :       0x0                    // 2
     206           1 :   };
     207           1 :   ExpectVerifies(ArrayVector(data), 1, 0);
     208           1 : }
     209             : 
     210       15128 : TEST_F(WasmStreamingDecoderTest, OneShortSection_b) {
     211             :   const uint8_t data[] = {
     212             :       U32_LE(kWasmMagic),    // --
     213             :       U32_LE(kWasmVersion),  // --
     214             :       0x1,                   // Section ID
     215             :       0x82,                  // Section Length = 2 (LEB)
     216             :       0x80,                  // --
     217             :       0x0,                   // --
     218             :       0x0,                   // Payload
     219             :       0x0                    // 2
     220           1 :   };
     221           1 :   ExpectVerifies(ArrayVector(data), 1, 0);
     222           1 : }
     223             : 
     224       15128 : TEST_F(WasmStreamingDecoderTest, OneEmptySection) {
     225             :   const uint8_t data[] = {
     226             :       U32_LE(kWasmMagic),    // --
     227             :       U32_LE(kWasmVersion),  // --
     228             :       0x1,                   // Section ID
     229             :       0x0                    // Section Length
     230           1 :   };
     231           1 :   ExpectVerifies(ArrayVector(data), 1, 0);
     232           1 : }
     233             : 
     234       15128 : TEST_F(WasmStreamingDecoderTest, OneSectionNotEnoughPayload1) {
     235             :   const uint8_t data[] = {
     236             :       U32_LE(kWasmMagic),    // --
     237             :       U32_LE(kWasmVersion),  // --
     238             :       0x1,                   // Section ID
     239             :       0x6,                   // Section Length
     240             :       0x0,                   // Payload
     241             :       0x0,                   // 2
     242             :       0x0,                   // 3
     243             :       0x0,                   // 4
     244             :       0x0                    // 5
     245           1 :   };
     246           1 :   ExpectFailure(ArrayVector(data));
     247           1 : }
     248             : 
     249       15128 : TEST_F(WasmStreamingDecoderTest, OneSectionNotEnoughPayload2) {
     250             :   const uint8_t data[] = {
     251             :       U32_LE(kWasmMagic),    // --
     252             :       U32_LE(kWasmVersion),  // --
     253             :       0x1,                   // Section ID
     254             :       0x6,                   // Section Length
     255             :       0x0                    // Payload
     256           1 :   };
     257           1 :   ExpectFailure(ArrayVector(data));
     258           1 : }
     259             : 
     260       15128 : TEST_F(WasmStreamingDecoderTest, OneSectionInvalidLength) {
     261             :   const uint8_t data[] = {
     262             :       U32_LE(kWasmMagic),    // --
     263             :       U32_LE(kWasmVersion),  // --
     264             :       0x1,                   // Section ID
     265             :       0x80,                  // Section Length (0 in LEB)
     266             :       0x80,                  // --
     267             :       0x80,                  // --
     268             :       0x80,                  // --
     269             :       0x80,                  // --
     270           1 :   };
     271           1 :   ExpectFailure(ArrayVector(data));
     272           1 : }
     273             : 
     274       15128 : TEST_F(WasmStreamingDecoderTest, TwoLongSections) {
     275             :   const uint8_t data[] = {
     276             :       U32_LE(kWasmMagic),    // --
     277             :       U32_LE(kWasmVersion),  // --
     278             :       0x1,                   // Section ID
     279             :       0x6,                   // Section Length
     280             :       0x0,                   // Payload
     281             :       0x0,                   // 2
     282             :       0x0,                   // 3
     283             :       0x0,                   // 4
     284             :       0x0,                   // 5
     285             :       0x0,                   // 6
     286             :       0x2,                   // Section ID
     287             :       0x7,                   // Section Length
     288             :       0x0,                   // Payload
     289             :       0x0,                   // 2
     290             :       0x0,                   // 3
     291             :       0x0,                   // 4
     292             :       0x0,                   // 5
     293             :       0x0,                   // 6
     294             :       0x0                    // 7
     295           1 :   };
     296           1 :   ExpectVerifies(ArrayVector(data), 2, 0);
     297           1 : }
     298             : 
     299       15128 : TEST_F(WasmStreamingDecoderTest, TwoShortSections) {
     300             :   const uint8_t data[] = {
     301             :       U32_LE(kWasmMagic),    // --
     302             :       U32_LE(kWasmVersion),  // --
     303             :       0x1,                   // Section ID
     304             :       0x1,                   // Section Length
     305             :       0x0,                   // Payload
     306             :       0x2,                   // Section ID
     307             :       0x2,                   // Section Length
     308             :       0x0,                   // Payload
     309             :       0x0,                   // 2
     310           1 :   };
     311           1 :   ExpectVerifies(ArrayVector(data), 2, 0);
     312           1 : }
     313             : 
     314       15128 : TEST_F(WasmStreamingDecoderTest, TwoSectionsShortLong) {
     315             :   const uint8_t data[] = {
     316             :       U32_LE(kWasmMagic),    // --
     317             :       U32_LE(kWasmVersion),  // --
     318             :       0x1,                   // Section ID
     319             :       0x1,                   // Section Length
     320             :       0x0,                   // Payload
     321             :       0x2,                   // Section ID
     322             :       0x7,                   // Section Length
     323             :       0x0,                   // Payload
     324             :       0x0,                   // 2
     325             :       0x0,                   // 3
     326             :       0x0,                   // 4
     327             :       0x0,                   // 5
     328             :       0x0,                   // 6
     329             :       0x0                    // 7
     330           1 :   };
     331           1 :   ExpectVerifies(ArrayVector(data), 2, 0);
     332           1 : }
     333             : 
     334       15128 : TEST_F(WasmStreamingDecoderTest, TwoEmptySections) {
     335             :   const uint8_t data[] = {
     336             :       U32_LE(kWasmMagic),    // --
     337             :       U32_LE(kWasmVersion),  // --
     338             :       0x1,                   // Section ID
     339             :       0x0,                   // Section Length
     340             :       0x2,                   // Section ID
     341             :       0x0                    // Section Length
     342           1 :   };
     343           1 :   ExpectVerifies(ArrayVector(data), 2, 0);
     344           1 : }
     345             : 
     346       15128 : TEST_F(WasmStreamingDecoderTest, OneFunction) {
     347             :   const uint8_t data[] = {
     348             :       U32_LE(kWasmMagic),    // --
     349             :       U32_LE(kWasmVersion),  // --
     350             :       kCodeSectionCode,      // Section ID
     351             :       0x8,                   // Section Length
     352             :       0x1,                   // Number of Functions
     353             :       0x6,                   // Function Length
     354             :       0x0,                   // Function
     355             :       0x0,                   // 2
     356             :       0x0,                   // 3
     357             :       0x0,                   // 4
     358             :       0x0,                   // 5
     359             :       0x0,                   // 6
     360           1 :   };
     361           1 :   ExpectVerifies(ArrayVector(data), 0, 1);
     362           1 : }
     363             : 
     364       15128 : TEST_F(WasmStreamingDecoderTest, OneShortFunction) {
     365             :   const uint8_t data[] = {
     366             :       U32_LE(kWasmMagic),    // --
     367             :       U32_LE(kWasmVersion),  // --
     368             :       kCodeSectionCode,      // Section ID
     369             :       0x3,                   // Section Length
     370             :       0x1,                   // Number of Functions
     371             :       0x1,                   // Function Length
     372             :       0x0,                   // Function
     373           1 :   };
     374           1 :   ExpectVerifies(ArrayVector(data), 0, 1);
     375           1 : }
     376             : 
     377       15128 : TEST_F(WasmStreamingDecoderTest, EmptyFunction) {
     378             :   const uint8_t data[] = {
     379             :       U32_LE(kWasmMagic),    // --
     380             :       U32_LE(kWasmVersion),  // --
     381             :       kCodeSectionCode,      // Section ID
     382             :       0x2,                   // Section Length
     383             :       0x1,                   // Number of Functions
     384             :       0x0,                   // Function Length
     385           1 :   };
     386           1 :   ExpectFailure(ArrayVector(data));
     387           1 : }
     388             : 
     389       15128 : TEST_F(WasmStreamingDecoderTest, TwoFunctions) {
     390             :   const uint8_t data[] = {
     391             :       U32_LE(kWasmMagic),    // --
     392             :       U32_LE(kWasmVersion),  // --
     393             :       kCodeSectionCode,      // Section ID
     394             :       0x10,                  // Section Length
     395             :       0x2,                   // Number of Functions
     396             :       0x6,                   // Function Length
     397             :       0x0,                   // Function
     398             :       0x0,                   // 2
     399             :       0x0,                   // 3
     400             :       0x0,                   // 4
     401             :       0x0,                   // 5
     402             :       0x0,                   // 6
     403             :       0x7,                   // Function Length
     404             :       0x0,                   // Function
     405             :       0x0,                   // 2
     406             :       0x0,                   // 3
     407             :       0x0,                   // 4
     408             :       0x0,                   // 5
     409             :       0x0,                   // 6
     410             :       0x0,                   // 7
     411           1 :   };
     412           1 :   ExpectVerifies(ArrayVector(data), 0, 2);
     413           1 : }
     414             : 
     415       15128 : TEST_F(WasmStreamingDecoderTest, TwoFunctions_b) {
     416             :   const uint8_t data[] = {
     417             :       U32_LE(kWasmMagic),    // --
     418             :       U32_LE(kWasmVersion),  // --
     419             :       kCodeSectionCode,      // Section ID
     420             :       0xB,                   // Section Length
     421             :       0x2,                   // Number of Functions
     422             :       0x1,                   // Function Length
     423             :       0x0,                   // Function
     424             :       0x7,                   // Function Length
     425             :       0x0,                   // Function
     426             :       0x0,                   // 2
     427             :       0x0,                   // 3
     428             :       0x0,                   // 4
     429             :       0x0,                   // 5
     430             :       0x0,                   // 6
     431             :       0x0,                   // 7
     432           1 :   };
     433           1 :   ExpectVerifies(ArrayVector(data), 0, 2);
     434           1 : }
     435             : 
     436       15128 : TEST_F(WasmStreamingDecoderTest, CodeSectionLengthZero) {
     437             :   const uint8_t data[] = {
     438             :       U32_LE(kWasmMagic),    // --
     439             :       U32_LE(kWasmVersion),  // --
     440             :       kCodeSectionCode,      // Section ID
     441             :       0x0,                   // Section Length
     442           1 :   };
     443           1 :   ExpectFailure(ArrayVector(data));
     444           1 : }
     445             : 
     446       15128 : TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooHigh) {
     447             :   const uint8_t data[] = {
     448             :       U32_LE(kWasmMagic),    // --
     449             :       U32_LE(kWasmVersion),  // --
     450             :       kCodeSectionCode,      // Section ID
     451             :       0xD,                   // Section Length
     452             :       0x2,                   // Number of Functions
     453             :       0x7,                   // Function Length
     454             :       0x0,                   // Function
     455             :       0x0,                   // 2
     456             :       0x0,                   // 3
     457             :       0x0,                   // 4
     458             :       0x0,                   // 5
     459             :       0x0,                   // 6
     460             :       0x0,                   // 7
     461             :       0x1,                   // Function Length
     462             :       0x0,                   // Function
     463           1 :   };
     464           1 :   ExpectFailure(ArrayVector(data));
     465           1 : }
     466             : 
     467       15128 : TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooHighZeroFunctions) {
     468             :   const uint8_t data[] = {
     469             :       U32_LE(kWasmMagic),    // --
     470             :       U32_LE(kWasmVersion),  // --
     471             :       kCodeSectionCode,      // Section ID
     472             :       0xD,                   // Section Length
     473             :       0x0,                   // Number of Functions
     474           1 :   };
     475           1 :   ExpectFailure(ArrayVector(data));
     476           1 : }
     477             : 
     478       15128 : TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooLow) {
     479             :   const uint8_t data[] = {
     480             :       U32_LE(kWasmMagic),    // --
     481             :       U32_LE(kWasmVersion),  // --
     482             :       kCodeSectionCode,      // Section ID
     483             :       0x9,                   // Section Length
     484             :       0x2,                   // Number of Functions
     485             :       0x7,                   // Function Length
     486             :       0x0,                   // Function
     487             :       0x0,                   // 2
     488             :       0x0,                   // 3
     489             :       0x0,                   // 4
     490             :       0x0,                   // 5
     491             :       0x0,                   // 6
     492             :       0x0,                   // 7
     493             :       0x1,                   // Function Length
     494             :       0x0,                   // Function
     495           1 :   };
     496           1 :   ExpectFailure(ArrayVector(data));
     497           1 : }
     498             : 
     499       15128 : TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooLowEndsInNumFunctions) {
     500             :   const uint8_t data[] = {
     501             :       U32_LE(kWasmMagic),    // --
     502             :       U32_LE(kWasmVersion),  // --
     503             :       kCodeSectionCode,      // Section ID
     504             :       0x1,                   // Section Length
     505             :       0x82,                  // Number of Functions
     506             :       0x80,                  // --
     507             :       0x00,                  // --
     508             :       0x7,                   // Function Length
     509             :       0x0,                   // Function
     510             :       0x0,                   // 2
     511             :       0x0,                   // 3
     512             :       0x0,                   // 4
     513             :       0x0,                   // 5
     514             :       0x0,                   // 6
     515             :       0x0,                   // 7
     516             :       0x1,                   // Function Length
     517             :       0x0,                   // Function
     518           1 :   };
     519           1 :   ExpectFailure(ArrayVector(data));
     520           1 : }
     521             : 
     522       15128 : TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooLowEndsInFunctionLength) {
     523             :   const uint8_t data[] = {
     524             :       U32_LE(kWasmMagic),    // --
     525             :       U32_LE(kWasmVersion),  // --
     526             :       kCodeSectionCode,      // Section ID
     527             :       0x5,                   // Section Length
     528             :       0x82,                  // Number of Functions
     529             :       0x80,                  // --
     530             :       0x00,                  // --
     531             :       0x87,                  // Function Length
     532             :       0x80,                  // --
     533             :       0x00,                  // --
     534             :       0x0,                   // Function
     535             :       0x0,                   // 2
     536             :       0x0,                   // 3
     537             :       0x0,                   // 4
     538             :       0x0,                   // 5
     539             :       0x0,                   // 6
     540             :       0x0,                   // 7
     541             :       0x1,                   // Function Length
     542             :       0x0,                   // Function
     543           1 :   };
     544           1 :   ExpectFailure(ArrayVector(data));
     545           1 : }
     546             : 
     547       15128 : TEST_F(WasmStreamingDecoderTest, NumberOfFunctionsTooHigh) {
     548             :   const uint8_t data[] = {
     549             :       U32_LE(kWasmMagic),    // --
     550             :       U32_LE(kWasmVersion),  // --
     551             :       kCodeSectionCode,      // Section ID
     552             :       0xB,                   // Section Length
     553             :       0x4,                   // Number of Functions
     554             :       0x7,                   // Function Length
     555             :       0x0,                   // Function
     556             :       0x0,                   // 2
     557             :       0x0,                   // 3
     558             :       0x0,                   // 4
     559             :       0x0,                   // 5
     560             :       0x0,                   // 6
     561             :       0x0,                   // 7
     562             :       0x1,                   // Function Length
     563             :       0x0,                   // Function
     564           1 :   };
     565           1 :   ExpectFailure(ArrayVector(data));
     566           1 : }
     567             : 
     568       15128 : TEST_F(WasmStreamingDecoderTest, NumberOfFunctionsTooLow) {
     569             :   const uint8_t data[] = {
     570             :       U32_LE(kWasmMagic),    // --
     571             :       U32_LE(kWasmVersion),  // --
     572             :       kCodeSectionCode,      // Section ID
     573             :       0xE,                   // Section Length
     574             :       0x2,                   // Number of Functions
     575             :       0x1,                   // Function Length
     576             :       0x0,                   // Function
     577             :       0x2,                   // Function Length
     578             :       0x0,                   // Function
     579             :       0x0,                   // 2
     580             :       0x7,                   // Function Length
     581             :       0x0,                   // Function
     582             :       0x0,                   // 2
     583             :       0x0,                   // 3
     584             :       0x0,                   // 4
     585             :       0x0,                   // 5
     586             :       0x0,                   // 6
     587             :       0x0,                   // 7
     588           1 :   };
     589           1 :   ExpectFailure(ArrayVector(data));
     590           1 : }
     591             : 
     592       15128 : TEST_F(WasmStreamingDecoderTest, TwoCodeSections) {
     593             :   const uint8_t data[] = {
     594             :       U32_LE(kWasmMagic),    // --
     595             :       U32_LE(kWasmVersion),  // --
     596             :       kCodeSectionCode,      // Section ID
     597             :       0x3,                   // Section Length
     598             :       0x1,                   // Number of Functions
     599             :       0x1,                   // Function Length
     600             :       0x0,                   // Function
     601             :       kCodeSectionCode,      // Section ID
     602             :       0x3,                   // Section Length
     603             :       0x1,                   // Number of Functions
     604             :       0x1,                   // Function Length
     605             :       0x0,                   // Function
     606           1 :   };
     607           1 :   ExpectFailure(ArrayVector(data));
     608           1 : }
     609             : 
     610       15128 : TEST_F(WasmStreamingDecoderTest, UnknownSection) {
     611             :   const uint8_t data[] = {
     612             :       U32_LE(kWasmMagic),    // --
     613             :       U32_LE(kWasmVersion),  // --
     614             :       kCodeSectionCode,      // Section ID
     615             :       0x3,                   // Section Length
     616             :       0x1,                   // Number of Functions
     617             :       0x1,                   // Function Length
     618             :       0x0,                   // Function
     619             :       kUnknownSectionCode,   // Section ID
     620             :       0x3,                   // Section Length
     621             :       0x1,                   // Name Length
     622             :       0x1,                   // Name
     623             :       0x0,                   // Content
     624           1 :   };
     625           1 :   ExpectVerifies(ArrayVector(data), 1, 1);
     626           1 : }
     627             : 
     628       15128 : TEST_F(WasmStreamingDecoderTest, UnknownSectionSandwich) {
     629             :   const uint8_t data[] = {
     630             :       U32_LE(kWasmMagic),    // --
     631             :       U32_LE(kWasmVersion),  // --
     632             :       kCodeSectionCode,      // Section ID
     633             :       0x3,                   // Section Length
     634             :       0x1,                   // Number of Functions
     635             :       0x1,                   // Function Length
     636             :       0x0,                   // Function
     637             :       kUnknownSectionCode,   // Section ID
     638             :       0x3,                   // Section Length
     639             :       0x1,                   // Name Length
     640             :       0x1,                   // Name
     641             :       0x0,                   // Content
     642             :       kCodeSectionCode,      // Section ID
     643             :       0x3,                   // Section Length
     644             :       0x1,                   // Number of Functions
     645             :       0x1,                   // Function Length
     646             :       0x0,                   // Function
     647           1 :   };
     648           1 :   ExpectFailure(ArrayVector(data));
     649           1 : }
     650             : 
     651             : }  // namespace wasm
     652             : }  // namespace internal
     653        9075 : }  // namespace v8

Generated by: LCOV version 1.10