From e97e27b8d5524a0408b7789e51e219a1bfed2c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Van=20Canneyt?= Date: Sun, 17 Oct 2021 17:58:11 +0200 Subject: [PATCH] * Raise exception for fileseek positions that do not fit in longing. Issue #39407 --- rtl/objpas/sysconst.pp | 1 + rtl/unix/sysutils.pp | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/rtl/objpas/sysconst.pp b/rtl/objpas/sysconst.pp index 6aafbe4a68..eefa10b1a8 100644 --- a/rtl/objpas/sysconst.pp +++ b/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'; diff --git a/rtl/unix/sysutils.pp b/rtl/unix/sysutils.pp index 9077ee40a2..071f8b3419 100644 --- a/rtl/unix/sysutils.pp +++ b/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;