LCOV - code coverage report
Current view: top level - test/unittests/wasm - streaming-decoder-unittest.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 192 195 98.5 %
Date: 2019-02-19 Functions: 79 117 67.5 %

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

Generated by: LCOV version 1.10