Browse Source

* Fix 19850 (modified patch by Chad B)

git-svn-id: trunk@18191 -
michael 14 years ago
parent
commit
2777349a23
1 changed files with 18 additions and 18 deletions
  1. 18 18
      packages/fcl-base/src/idea.pp

+ 18 - 18
packages/fcl-base/src/idea.pp

@@ -78,8 +78,10 @@ Type
     FKey    : TIDEAKey;
     FKey    : TIDEAKey;
     FData   : TIDEACryptData;
     FData   : TIDEACryptData;
     FBufpos : Byte;
     FBufpos : Byte;
-    FPos    : Longint;
+    FPos    : Int64;
   Protected
   Protected
+    function GetPosition: Int64; override;
+    procedure InvalidSeek; override;
     Procedure CreateCryptKey(Const S : String; Var Key : TIDEACryptKey);
     Procedure CreateCryptKey(Const S : String; Var Key : TIDEACryptKey);
   Public
   Public
     Constructor Create(AKey : TIDEAKey; Dest: TStream); overload;
     Constructor Create(AKey : TIDEAKey; Dest: TStream); overload;
@@ -103,7 +105,7 @@ Type
   public
   public
     Constructor Create(Const AKey : String; Dest: TStream); overload;
     Constructor Create(Const AKey : String; Dest: TStream); overload;
     function Read(var Buffer; Count: Longint): Longint; override;
     function Read(var Buffer; Count: Longint): Longint; override;
-    function Seek(Offset: Longint; Origin: Word): Longint; override;
+    function Seek(const Offset: int64; Origin: TSeekOrigin): int64; override;
   end;
   end;
 
 
 Implementation
 Implementation
@@ -266,6 +268,16 @@ begin
   Fpos:=0;
   Fpos:=0;
 end;
 end;
 
 
+function TIDEAStream.GetPosition: Int64;
+begin
+  Result:=FPos;
+end;
+
+procedure TIDEAStream.InvalidSeek;
+begin
+  Raise EIDEAError.Create(SNoSeekAllowed);
+end;
+
 procedure TIDEAStream.CreateCryptKey(const S: String; var Key: TIDEACryptKey);
 procedure TIDEAStream.CreateCryptKey(const S: String; var Key: TIDEACryptKey);
 
 
 Var
 Var
@@ -359,7 +371,7 @@ begin
   if (Offset = 0) and (Origin = soFromCurrent) then
   if (Offset = 0) and (Origin = soFromCurrent) then
     Result := FPos
     Result := FPos
   else
   else
-    Raise EIDEAError.Create(SNoSeekAllowed);
+    InvalidSeek;
 end;
 end;
 
 
 
 
@@ -422,23 +434,11 @@ begin
   Inc(FPos,Result);
   Inc(FPos,Result);
 end;
 end;
 
 
-function TIDEADeCryptStream.Seek(Offset: Longint; Origin: Word): Longint;
-
-Var Buffer : Array[0..1023] of byte;
-    i : longint;
+function TIDEADeCryptStream.Seek(const Offset: int64; Origin: TSeekOrigin): int64;
 
 
 begin
 begin
-  // Fake seek if possible by reading and discarding bytes.
-  If ((Offset>=0) and (Origin = soFromCurrent)) or
-    ((Offset>FPos) and (Origin = soFromBeginning)) then
-      begin
-      For I:=1 to (Offset div SizeOf(Buffer)) do
-        ReadBuffer(Buffer,SizeOf(Buffer));
-      ReadBuffer(Buffer,Offset mod SizeOf(Buffer));
-      Result:=FPos;
-      end
-  else
-    Raise EIDEAError.Create(SNoSeekAllowed);
+  FakeSeekForward(Offset,Origin,fpos);
+  Result:=FPos; // FPos updated by read
 end;
 end;
 
 
 END.
 END.