浏览代码

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

git-svn-id: trunk@5595 -

Jonas Maebe 18 年之前
父节点
当前提交
26f81bfe08
共有 4 个文件被更改,包括 10 次插入6 次删除
  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}
 {$endif Test_Double_checksum}
 
 
 const
 const
-  CurrentPPUVersion=69;
+  CurrentPPUVersion=70;
 
 
 { buffer sizes }
 { buffer sizes }
   maxentrysize = 1024;
   maxentrysize = 1024;

+ 3 - 2
compiler/symdef.pas

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

+ 5 - 2
compiler/symtable.pas

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

+ 1 - 1
compiler/utils/ppudump.pp

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