瀏覽代碼

* Raise exception for fileseek positions that do not fit in longing. Issue #39407

Michaël Van Canneyt 3 年之前
父節點
當前提交
e97e27b8d5
共有 2 個文件被更改,包括 8 次插入1 次删除
  1. 1 0
      rtl/objpas/sysconst.pp
  2. 7 1
      rtl/unix/sysutils.pp

+ 1 - 0
rtl/objpas/sysconst.pp

@@ -41,6 +41,7 @@ const
   SDispatchError         = 'No variant method call dispatch';
   SDivByZero             = 'Division by zero';
   SEndOfFile             = 'Read past end of file';
+  SErrPosToBigForLongint = 'File position %d too big to fit in 32-bit integer; Use Int64 overload instead';
   SErrInvalidDateMonthWeek = 'Year %d, month %d, Week %d and day %d is not a valid date.';
   SerrInvalidHourMinuteSecMsec = '%d:%d:%d.%d is not a valid time specification';
   SErrInvalidDateWeek    = '%d %d %d is not a valid dateweek';

+ 7 - 1
rtl/unix/sysutils.pp

@@ -525,8 +525,14 @@ end;
 
 Function FileSeek (Handle,FOffset,Origin : Longint) : Longint;
 
+Var
+  I : Int64;
+
 begin
-  result:=longint(FileSeek(Handle,int64(FOffset),Origin));
+  I:=FileSeek(Handle,int64(FOffset),Origin);
+  if I>High(Longint) then
+     Raise EInOutError.CreateFmt(SErrPosToBigForLongint,[I]);
+  result:=I;
 end;