Browse Source

+ read the functions count from the functions section

Nikolay Nikolov 1 year ago
parent
commit
c7880e7bd1
1 changed files with 17 additions and 0 deletions
  1. 17 0
      compiler/ogwasm.pas

+ 17 - 0
compiler/ogwasm.pas

@@ -2546,6 +2546,8 @@ implementation
           end;
 
         function ReadFunctionSection: Boolean;
+          var
+            FunctionsCount: uint64;
           begin
             Result:=False;
             if FunctionSectionRead then
@@ -2554,6 +2556,21 @@ implementation
                 exit;
               end;
             FunctionSectionRead:=True;
+            if not ReadUleb(AReader,FunctionsCount) then
+              begin
+                InputError('Error reading the functions count');
+                exit;
+              end;
+            if AReader.Pos>(SectionStart+SectionSize) then
+              begin
+                InputError('The functions count stretches beyond the end of the function section');
+                exit;
+              end;
+            if FunctionsCount>high(uint32) then
+              begin
+                InputError('The functions count does not fit in an unsigned 32-bit int');
+                exit;
+              end;
           end;
 
         function ReadGlobalSection: Boolean;