Browse Source

+ 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 1 year ago
parent
commit
e4600f5e38
1 changed files with 17 additions and 0 deletions
  1. 17 0
      compiler/ogwasm.pas

+ 17 - 0
compiler/ogwasm.pas

@@ -2731,6 +2731,8 @@ implementation
           end;
 
         function ReadDataSection: Boolean;
+          var
+            DataCount: uint32;
           begin
             Result:=False;
             if DataSectionRead then
@@ -2739,6 +2741,21 @@ implementation
                 exit;
               end;
             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;
 
         function ReadDataCountSection: Boolean;