瀏覽代碼

+ read the data count from the data section. Set size of the DataSegments
array, if the data count section hasn't been encountered. Compare the count
with the value from the data count section, in case the data count section
has been encountered, and issue an error, if they differ.

Nikolay Nikolov 2 年之前
父節點
當前提交
e4600f5e38
共有 1 個文件被更改,包括 17 次插入0 次删除
  1. 17 0
      compiler/ogwasm.pas

+ 17 - 0
compiler/ogwasm.pas

@@ -2731,6 +2731,8 @@ implementation
           end;
           end;
 
 
         function ReadDataSection: Boolean;
         function ReadDataSection: Boolean;
+          var
+            DataCount: uint32;
           begin
           begin
             Result:=False;
             Result:=False;
             if DataSectionRead then
             if DataSectionRead then
@@ -2739,6 +2741,21 @@ implementation
                 exit;
                 exit;
               end;
               end;
             DataSectionRead:=True;
             DataSectionRead:=True;
+            if not ReadUleb32(DataCount) then
+              begin
+                InputError('Error reading the data entries count from the data section');
+                exit;
+              end;
+            if DataCountSectionRead then
+              begin
+                if Length(DataSegments)<>DataCount then
+                  begin
+                    InputError('Data entries count in the data section do not match the number, specified in the data count section');
+                    exit
+                  end;
+              end
+            else
+              SetLength(DataSegments,DataCount);
           end;
           end;
 
 
         function ReadDataCountSection: Boolean;
         function ReadDataCountSection: Boolean;