Browse Source

+ parse the WASM_SEGMENT_INFO subsection

Nikolay Nikolov 1 year ago
parent
commit
3121ee1367
1 changed files with 38 additions and 1 deletions
  1. 38 1
      compiler/ogwasm.pas

+ 38 - 1
compiler/ogwasm.pas

@@ -2234,8 +2234,41 @@ implementation
           function ReadLinkingSection: Boolean;
           function ReadLinkingSection: Boolean;
 
 
             function ReadSegmentInfo: Boolean;
             function ReadSegmentInfo: Boolean;
+              var
+                SegmentCount, SegAlignment, SegFlags: uint32;
+                i: Integer;
+                SegName: ansistring;
               begin
               begin
                 Result:=False;
                 Result:=False;
+                if not ReadUleb32(SegmentCount) then
+                  begin
+                    InputError('Error reading the segment count from the WASM_SEGMENT_INFO subsection of the ''linking'' section');
+                    exit;
+                  end;
+                for i:=0 to SegmentCount-1 do
+                  begin
+                    if not ReadName(SegName) then
+                      begin
+                        InputError('Error reading segment name from the WASM_SEGMENT_INFO subsection of the ''linking'' section');
+                        exit;
+                      end;
+                    if not ReadUleb32(SegAlignment) then
+                      begin
+                        InputError('Error reading segment alignment from the WASM_SEGMENT_INFO subsection of the ''linking'' section');
+                        exit;
+                      end;
+                    if not ReadUleb32(SegFlags) then
+                      begin
+                        InputError('Error reading segment flags from the WASM_SEGMENT_INFO subsection of the ''linking'' section');
+                        exit;
+                      end;
+                  end;
+                if AReader.Pos<>(SectionStart+SectionSize) then
+                  begin
+                    InputError('Unexpected WASM_SEGMENT_INFO section size');
+                    exit;
+                  end;
+                Result:=True;
               end;
               end;
 
 
             function ReadSymbolTable: Boolean;
             function ReadSymbolTable: Boolean;
@@ -2284,7 +2317,11 @@ implementation
                   SectionSize:=SubsectionSize;
                   SectionSize:=SubsectionSize;
                   case SubsectionType of
                   case SubsectionType of
                     Byte(WASM_SEGMENT_INFO):
                     Byte(WASM_SEGMENT_INFO):
-                      result:=ReadSegmentInfo;
+                      if not ReadSegmentInfo then
+                        begin
+                          InputError('Error reading the WASM_SEGMENT_INFO subsection of the ''linking'' section');
+                          exit;
+                        end;
                     Byte(WASM_SYMBOL_TABLE):
                     Byte(WASM_SYMBOL_TABLE):
                       result:=ReadSymbolTable;
                       result:=ReadSymbolTable;
                     else
                     else