View Issue Details

IDProjectCategoryView StatusLast Update
0035724FPCFCLpublic2019-06-21 09:05
ReporterOndrej PokornyAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Product Version3.3.1Product Build 
Target VersionFixed in Version3.3.1 
Summary0035724: [Patch] Add support for TBlowFishDeCryptStream.Position := 0
DescriptionTBlowFishDeCryptStream doesn't allow seeking backwards. This patch allows to seek to the beginning of the stream (=rewind the stream).
TagsNo tags attached.
Fixed in Revision42250
FPCOldBugId
FPCTarget3.2.0
Attached Files
  • blowfish-position0.patch (1,927 bytes)
    Index: packages/fcl-base/src/blowfish.pp
    ===================================================================
    --- packages/fcl-base/src/blowfish.pp	(revision 42238)
    +++ packages/fcl-base/src/blowfish.pp	(working copy)
    @@ -59,8 +59,8 @@
         function GetPosition: Int64; override;
         procedure InvalidSeek; override;
       Public
    -    Constructor Create(AKey : TBlowFishKey; AKeySize : Byte; Dest: TStream);
    -    Constructor Create(Const KeyPhrase : String; Dest: TStream);
    +    Constructor Create(AKey : TBlowFishKey; AKeySize : Byte; Dest: TStream); overload; virtual;
    +    Constructor Create(Const KeyPhrase : String; Dest: TStream); overload;
         Destructor Destroy; override;
         Property BlowFish : TBlowFish Read FBF;
       end;
    @@ -74,7 +74,11 @@
       end;
     
       TBlowFishDeCryptStream = Class(TBlowFishStream)
    +  private
    +    FSourcePos0: Int64;
       public
    +    Constructor Create(AKey : TBlowFishKey; AKeySize : Byte; Dest: TStream); override;
    +
         function Read(var Buffer; Count: Longint): Longint; override;
         function Seek(const Offset: Int64; Origin: TSeekOrigin): Int64; override;
       end;
    @@ -652,7 +656,14 @@
         TBlowFishDecryptStream
       ---------------------------------------------------------------------}
     
    +constructor TBlowFishDeCryptStream.Create(AKey: TBlowFishKey; AKeySize: Byte;
    +  Dest: TStream);
    +begin
    +  inherited Create(AKey, AKeySize, Dest);
     
    +  FSourcePos0 := Source.Position;
    +end;
    +
     function TBlowFishDeCryptStream.Read(var Buffer; Count: Longint): Longint;
     
     Var
    @@ -697,7 +708,13 @@
     function TBlowFishDeCryptStream.Seek(const Offset: Int64; Origin: TSeekOrigin): Int64;
     
     begin
    -  FakeSeekForward(Offset,TSeekOrigin(Origin),FPos);
    +  if (Offset=0) and (Origin=soBeginning) then
    +  begin // support seek to beginning
    +    FBufPos:=0;
    +    FPos:=0;
    +    Source.Position := FSourcePos0;
    +  end else
    +    FakeSeekForward(Offset,TSeekOrigin(Origin),FPos);
       Result:=FPos;
     end;
     
    
    blowfish-position0.patch (1,927 bytes)

Activities

Ondrej Pokorny

2019-06-16 14:23

reporter  

blowfish-position0.patch (1,927 bytes)
Index: packages/fcl-base/src/blowfish.pp
===================================================================
--- packages/fcl-base/src/blowfish.pp	(revision 42238)
+++ packages/fcl-base/src/blowfish.pp	(working copy)
@@ -59,8 +59,8 @@
     function GetPosition: Int64; override;
     procedure InvalidSeek; override;
   Public
-    Constructor Create(AKey : TBlowFishKey; AKeySize : Byte; Dest: TStream);
-    Constructor Create(Const KeyPhrase : String; Dest: TStream);
+    Constructor Create(AKey : TBlowFishKey; AKeySize : Byte; Dest: TStream); overload; virtual;
+    Constructor Create(Const KeyPhrase : String; Dest: TStream); overload;
     Destructor Destroy; override;
     Property BlowFish : TBlowFish Read FBF;
   end;
@@ -74,7 +74,11 @@
   end;
 
   TBlowFishDeCryptStream = Class(TBlowFishStream)
+  private
+    FSourcePos0: Int64;
   public
+    Constructor Create(AKey : TBlowFishKey; AKeySize : Byte; Dest: TStream); override;
+
     function Read(var Buffer; Count: Longint): Longint; override;
     function Seek(const Offset: Int64; Origin: TSeekOrigin): Int64; override;
   end;
@@ -652,7 +656,14 @@
     TBlowFishDecryptStream
   ---------------------------------------------------------------------}
 
+constructor TBlowFishDeCryptStream.Create(AKey: TBlowFishKey; AKeySize: Byte;
+  Dest: TStream);
+begin
+  inherited Create(AKey, AKeySize, Dest);
 
+  FSourcePos0 := Source.Position;
+end;
+
 function TBlowFishDeCryptStream.Read(var Buffer; Count: Longint): Longint;
 
 Var
@@ -697,7 +708,13 @@
 function TBlowFishDeCryptStream.Seek(const Offset: Int64; Origin: TSeekOrigin): Int64;
 
 begin
-  FakeSeekForward(Offset,TSeekOrigin(Origin),FPos);
+  if (Offset=0) and (Origin=soBeginning) then
+  begin // support seek to beginning
+    FBufPos:=0;
+    FPos:=0;
+    Source.Position := FSourcePos0;
+  end else
+    FakeSeekForward(Offset,TSeekOrigin(Origin),FPos);
   Result:=FPos;
 end;
 
blowfish-position0.patch (1,927 bytes)

Michael Van Canneyt

2019-06-19 14:26

administrator   ~0116788

Checked and applied. (although if you support going back to zero, you can support forwarding to every position...)

Ondrej Pokorny

2019-06-21 09:05

reporter   ~0116811

Yes, you are right - I didn't realize this in the beginning. Thanks.

Issue History

Date Modified Username Field Change
2019-06-16 14:23 Ondrej Pokorny New Issue
2019-06-16 14:23 Ondrej Pokorny File Added: blowfish-position0.patch
2019-06-19 14:26 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-06-19 14:26 Michael Van Canneyt Status new => resolved
2019-06-19 14:26 Michael Van Canneyt Resolution open => fixed
2019-06-19 14:26 Michael Van Canneyt Fixed in Version => 3.3.1
2019-06-19 14:26 Michael Van Canneyt Fixed in Revision => 42250
2019-06-19 14:26 Michael Van Canneyt FPCTarget => 3.2.0
2019-06-19 14:26 Michael Van Canneyt Note Added: 0116788
2019-06-21 09:05 Ondrej Pokorny Status resolved => closed
2019-06-21 09:05 Ondrej Pokorny Note Added: 0116811