Ver Fonte

* fixed arithmetic overflow when loading the recorddef of large
(> high(aint)/8 bytes) records from ppu files

git-svn-id: trunk@5595 -

Jonas Maebe há 18 anos atrás
pai
commit
26f81bfe08
4 ficheiros alterados com 10 adições e 6 exclusões
  1. 1 1
      compiler/ppu.pas
  2. 3 2
      compiler/symdef.pas
  3. 5 2
      compiler/symtable.pas
  4. 1 1
      compiler/utils/ppudump.pp

+ 1 - 1
compiler/ppu.pas

@@ -43,7 +43,7 @@ type
 {$endif Test_Double_checksum}
 
 const
-  CurrentPPUVersion=69;
+  CurrentPPUVersion=70;
 
 { buffer sizes }
   maxentrysize = 1024;

+ 3 - 2
compiler/symdef.pas

@@ -2426,11 +2426,12 @@ implementation
       begin
          inherited ppuload(recorddef,ppufile);
          symtable:=trecordsymtable.create(0);
-         trecordsymtable(symtable).datasize:=ppufile.getaint;
          trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
          trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
          trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
          trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
+         { requires usefieldalignment to be set }
+         trecordsymtable(symtable).datasize:=ppufile.getaint;
          trecordsymtable(symtable).ppuload(ppufile);
          symtable.defowner:=self;
          isunion:=false;
@@ -2486,11 +2487,11 @@ implementation
     procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
       begin
          inherited ppuwrite(ppufile);
-         ppufile.putaint(trecordsymtable(symtable).datasize);
          ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
          ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
          ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
          ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
+         ppufile.putaint(trecordsymtable(symtable).datasize);
          ppufile.writeentry(ibrecorddef);
          trecordsymtable(symtable).ppuwrite(ppufile);
       end;

+ 5 - 2
compiler/symtable.pas

@@ -913,7 +913,9 @@ implementation
     procedure tabstractrecordsymtable.setdatasize(val: aint);
       begin
         _datasize:=val;
-        databitsize:=val*8;
+        if (usefieldalignment=bit_alignment) then
+          { can overflow in non bitpacked records }
+          databitsize:=val*8;
       end;
 
 {****************************************************************************
@@ -943,7 +945,8 @@ implementation
         storesize:=_datasize;
         storealign:=fieldalignment;
         _datasize:=offset;
-        databitsize:=offset*8;
+        if (usefieldalignment=bit_alignment) then
+          databitsize:=offset*8;
 
         { We move the ownership of the defs and symbols to the new recordsymtable.
           The old unionsymtable keeps the references, but doesn't own the

+ 1 - 1
compiler/utils/ppudump.pp

@@ -1831,11 +1831,11 @@ begin
          ibrecorddef :
            begin
              readcommondef('Record definition');
-             writeln(space,'         DataSize : ',getaint);
              writeln(space,'       FieldAlign : ',getbyte);
              writeln(space,'      RecordAlign : ',getbyte);
              writeln(space,'         PadAlign : ',getbyte);
              writeln(space,'UseFieldAlignment : ',getbyte);
+             writeln(space,'         DataSize : ',getaint);
              if not EndOfEntry then
               Writeln('!! Entry has more information stored');
              {read the record definitions and symbols}