@@ -166,12 +166,18 @@ WasmBinaryReader::ProcessSection(SectionCode sectionId, bool isEntry /*= true*/)
166166 break ; // This section is not used by bytecode generator, stay in decoder
167167 }
168168 case bSectDataSegments:
169- // TODO: Populate Data entry info
170- ReadConst<UINT32>(); // dest addr in module memory
171- ReadConst<UINT32>(); // source offset (?)
172- ReadConst<UINT32>(); // size
173- ReadConst<UINT8>(); // init
174- m_moduleState.count ++;
169+ m_moduleState.size = LEB128 (length);
170+ if (m_moduleState.size == 0 )
171+ {
172+ // TODO: Probably can factor this out and validate all count fields.
173+ ThrowDecodingError (_u (" Illegal data segment entry count" ));
174+ }
175+ m_moduleInfo->AllocateDataSegs (m_moduleState.size );
176+ for (m_moduleState.count = 0 ; m_moduleState.count < m_moduleState.size ; m_moduleState.count ++)
177+ {
178+ TRACE_WASM_DECODER (L" Data Segment #%u" , m_moduleState.count );
179+ DataSegment ();
180+ }
175181 break ; // This section is not used by bytecode generator, stay in decoder
176182
177183 case bSectFunctionSignatures:
@@ -641,6 +647,18 @@ WasmBinaryReader::FunctionBodyHeader()
641647 }
642648}
643649
650+ void
651+ WasmBinaryReader::DataSegment ()
652+ {
653+ UINT len = 0 ;
654+ UINT32 offset = LEB128 (len);
655+ UINT32 dataByteLen = LEB128 (len);
656+ WasmDataSegment *dseg = Anew (&m_alloc, WasmDataSegment, &m_alloc, offset, dataByteLen, m_pc);
657+ CheckBytesLeft (dataByteLen);
658+ m_pc += dataByteLen;
659+ m_moduleInfo->AddDataSeg (dseg, m_moduleState.count );
660+ }
661+
644662char16* WasmBinaryReader::ReadInlineName (uint32& length, uint32& nameLength)
645663{
646664 nameLength = LEB128 (length);
@@ -671,7 +689,7 @@ WasmBinaryReader::ImportEntry()
671689
672690 if (sigId >= m_moduleInfo->GetSignatureCount ())
673691 {
674- ThrowDecodingError (L " Function signature is out of bound" );
692+ ThrowDecodingError (_u ( " Function signature is out of bound" ) );
675693 }
676694
677695 wchar_t * modName = ReadInlineName (len, modNameLen);
0 commit comments