Browse Source

+ wasm internal object reader: added range check to the reader of the SymKind field

Nikolay Nikolov 1 year ago
parent
commit
b35c118244
1 changed files with 8 additions and 1 deletions
  1. 8 1
      compiler/ogwasm.pas

+ 8 - 1
compiler/ogwasm.pas

@@ -2752,6 +2752,7 @@ implementation
                 SymCount: uint32;
                 i: Integer;
                 SymKindName: string;
+                SymKindB: Byte;
               begin
                 Result:=False;
                 if SymbolTableSectionRead then
@@ -2769,11 +2770,17 @@ implementation
                 for i:=0 to SymCount-1 do
                   with SymbolTable[i] do
                     begin
-                      if not Read(SymKind,1) then
+                      if not Read(SymKindB,1) then
                         begin
                           InputError('Error reading symbol type from the WASM_SYMBOL_TABLE subsection of the ''linking'' section');
                           exit;
                         end;
+                      if (SymKindB<Low(Ord(TWasmSymbolType))) or (SymKindB>High(Ord(TWasmSymbolType))) then
+                        begin
+                          InputError('Unsupported symbol type from the WASM_SYMBOL_TABLE subsection of the ''linking'' section');
+                          exit;
+                        end;
+                      SymKind:=TWasmSymbolType(SymKindB);
                       if not ReadUleb32(SymFlags) then
                         begin
                           InputError('Error reading symbol flags from the WASM_SYMBOL_TABLE subsection of the ''linking'' section');