Changeset 209651 in webkit for trunk/Source/JavaScriptCore/wasm/WasmModuleParser.cpp
- Timestamp:
- Dec 9, 2016, 11:08:31 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/wasm/WasmModuleParser.cpp
r209642 r209651 158 158 { 159 159 uint32_t count; 160 if (!parseVarUInt32(count)) 160 if (!parseVarUInt32(count) 161 || count == std::numeric_limits<uint32_t>::max() 162 || !m_module->signatures.tryReserveCapacity(count)) 161 163 return false; 162 164 if (verbose) 163 dataLogLn("count: ", count); 164 if (!m_module->signatures.tryReserveCapacity(count)) 165 return false; 165 dataLogLn(" count: ", count); 166 166 167 167 for (uint32_t i = 0; i < count; ++i) { … … 176 176 177 177 uint32_t argumentCount; 178 if (!parseVarUInt32(argumentCount))179 return false;180 181 if (verbose)182 dataLogLn("argumentCount: ", argumentCount);183 184 178 Vector<Type> argumentTypes; 185 if (!argumentTypes.tryReserveCapacity(argumentCount)) 186 return false; 187 188 for (unsigned i = 0; i != argumentCount; ++i) { 179 if (!parseVarUInt32(argumentCount) 180 || argumentCount == std::numeric_limits<uint32_t>::max() 181 || !argumentTypes.tryReserveCapacity(argumentCount)) 182 return false; 183 if (verbose) 184 dataLogLn(" argument count: ", argumentCount); 185 186 for (unsigned i = 0; i < argumentCount; ++i) { 189 187 Type argumentType; 190 188 if (!parseResultType(argumentType)) … … 217 215 { 218 216 uint32_t importCount; 219 if (!parseVarUInt32(importCount) )220 return false;221 if (!m_module->imports.tryReserveCapacity(importCount) // FIXME this over-allocates when we fix the FIXMEs below.217 if (!parseVarUInt32(importCount) 218 || importCount == std::numeric_limits<uint32_t>::max() 219 || !m_module->imports.tryReserveCapacity(importCount) // FIXME this over-allocates when we fix the FIXMEs below. 222 220 || !m_module->importFunctions.tryReserveCapacity(importCount) // FIXME this over-allocates when we fix the FIXMEs below. 223 221 || !m_functionIndexSpace.tryReserveCapacity(importCount)) // FIXME this over-allocates when we fix the FIXMEs below. We'll allocate some more here when we know how many functions to expect. 224 222 return false; 225 223 226 for (uint32_t importNumber = 0; importNumber !=importCount; ++importNumber) {224 for (uint32_t importNumber = 0; importNumber < importCount; ++importNumber) { 227 225 Import imp; 228 226 uint32_t moduleLen; … … 279 277 uint32_t count; 280 278 if (!parseVarUInt32(count) 279 || count == std::numeric_limits<uint32_t>::max() 281 280 || !m_module->internalFunctionSignatures.tryReserveCapacity(count) 282 281 || !m_functionLocationInBinary.tryReserveCapacity(count) … … 284 283 return false; 285 284 286 for (uint32_t i = 0; i !=count; ++i) {285 for (uint32_t i = 0; i < count; ++i) { 287 286 uint32_t typeNumber; 288 287 if (!parseVarUInt32(typeNumber) … … 375 374 uint32_t exportCount; 376 375 if (!parseVarUInt32(exportCount) 376 || exportCount == std::numeric_limits<uint32_t>::max() 377 377 || !m_module->exports.tryReserveCapacity(exportCount)) 378 378 return false; 379 379 380 for (uint32_t exportNumber = 0; exportNumber !=exportCount; ++exportNumber) {380 for (uint32_t exportNumber = 0; exportNumber < exportCount; ++exportNumber) { 381 381 Export exp; 382 382 uint32_t fieldLen; … … 386 386 return false; 387 387 exp.field = Identifier::fromString(m_vm, fieldString); 388 388 389 if (!parseExternalKind(exp.kind)) 389 390 return false; 391 390 392 switch (exp.kind) { 391 393 case External::Function: { … … 441 443 uint32_t count; 442 444 if (!parseVarUInt32(count) 445 || count == std::numeric_limits<uint32_t>::max() 443 446 || count != m_functionLocationInBinary.size()) 444 447 return false; 445 448 446 for (uint32_t i = 0; i !=count; ++i) {449 for (uint32_t i = 0; i < count; ++i) { 447 450 uint32_t functionSize; 448 451 if (!parseVarUInt32(functionSize) … … 461 464 bool ModuleParser::parseData() 462 465 { 463 // FIXME https://bugs.webkit.org/show_bug.cgi?id=161709 464 RELEASE_ASSERT_NOT_REACHED(); 466 uint32_t segmentCount; 467 if (!parseVarUInt32(segmentCount) 468 || segmentCount == std::numeric_limits<uint32_t>::max() 469 || !m_module->data.tryReserveCapacity(segmentCount)) 470 return false; 471 if (verbose) 472 dataLogLn(" segments: ", segmentCount); 473 474 for (uint32_t segmentNumber = 0; segmentNumber < segmentCount; ++segmentNumber) { 475 if (verbose) 476 dataLogLn(" segment #", segmentNumber); 477 uint32_t index; 478 uint8_t opcode; 479 uint32_t offset; 480 uint8_t endOpcode; 481 uint32_t dataByteLength; 482 if (!parseVarUInt32(index) 483 || index) 484 return false; 485 486 // FIXME allow complex init_expr here. https://bugs.webkit.org/show_bug.cgi?id=165700 487 // For now we only handle i32.const as offset. 488 if (!parseUInt8(opcode) 489 || opcode != Wasm::I32Const 490 || !parseVarUInt32(offset) 491 || !parseUInt8(endOpcode) 492 || endOpcode != Wasm::End) 493 return false; 494 if (verbose) 495 dataLogLn(" offset: ", offset); 496 497 if (!parseVarUInt32(dataByteLength) 498 || dataByteLength == std::numeric_limits<uint32_t>::max()) 499 return false; 500 if (verbose) 501 dataLogLn(" data bytes: ", dataByteLength); 502 503 Segment* segment = Segment::make(offset, dataByteLength); 504 if (!segment) 505 return false; 506 m_module->data.uncheckedAppend(Segment::makePtr(segment)); 507 for (uint32_t dataByte = 0; dataByte < dataByteLength; ++dataByte) { 508 uint8_t byte; 509 if (!parseUInt8(byte)) 510 return false; 511 segment->byte(dataByte) = byte; 512 if (verbose) 513 dataLogLn(" [", dataByte, "] = ", segment->byte(dataByte)); 514 } 515 } 465 516 return true; 466 517 }
Note:
See TracChangeset
for help on using the changeset viewer.