Browse Source

+ started implementing the reading of relocation sections in the wasm object reader

Nikolay Nikolov 1 year ago
parent
commit
7f30a87651
1 changed files with 23 additions and 1 deletions
  1. 23 1
      compiler/ogwasm.pas

+ 23 - 1
compiler/ogwasm.pas

@@ -2356,8 +2356,24 @@ implementation
         function ReadCustomSection: Boolean;
         function ReadCustomSection: Boolean;
 
 
           function ReadRelocationSection: Boolean;
           function ReadRelocationSection: Boolean;
+            var
+              TargetSection, RelocCount: uint32;
+              i: Integer;
             begin
             begin
               Result:=False;
               Result:=False;
+              if not ReadUleb32(TargetSection) then
+                begin
+                  InputError('Error reading the index of the target section of a relocation section');
+                  exit;
+                end;
+              if not ReadUleb32(RelocCount) then
+                begin
+                  InputError('Error reading the relocation entries count from a relocation section');
+                  exit;
+                end;
+              for i:=0 to RelocCount-1 do
+                ;
+              Result:=True;
             end;
             end;
 
 
           function ReadLinkingSection: Boolean;
           function ReadLinkingSection: Boolean;
@@ -2607,7 +2623,13 @@ implementation
             Result:=False;
             Result:=False;
             ReadName(SectionName);
             ReadName(SectionName);
             if Copy(SectionName,1,Length(RelocationSectionPrefix)) = RelocationSectionPrefix then
             if Copy(SectionName,1,Length(RelocationSectionPrefix)) = RelocationSectionPrefix then
-              Result:=ReadRelocationSection
+              begin
+                if not ReadRelocationSection then
+                  begin
+                    InputError('Error reading the relocation section ''' + SectionName + '''');
+                    exit;
+                  end;
+              end
             else
             else
               case SectionName of
               case SectionName of
                 'linking':
                 'linking':