View Issue Details

IDProjectCategoryView StatusLast Update
0035161FPCFCLpublic2019-03-02 10:21
ReporterDoyenne Assigned ToMichael Van Canneyt  
Status resolvedResolutionfixed 
Target Version3.2.0Fixed in Version3.3.1 
Summary0035161: fcl-base/base64.pp: DecodeStringBase64('') raises exception
DescriptionIf DecodeStringBase64 is called with an empty string as parameter, it raises an exception.

Expected behaviour
I think it should return an empty string, as explained here:

In addition, the trunk version of base64.pp has the following code in EncodeStringBase64():
  if Length(s)=0 then

Therefore, '' is encoded into '' and as such, '' should be decoded into '' as well.

Reason of the exception
DecodeStringBase64() uses the following code:


Decoder.Size is correctly calculated as 0. If a stream's CopyFrom() is called with Size=0, it executes TStream.Position := 0. However, TBase64DecodingStream.Seek() is not yet implemented and raises an exception.

The solution is easy. In trunk, a check was added in EncodeStringBase64() (see above). The same check should be added to DecodeStringBase64() to solve the issue.

See attachment for diff.
TagsNo tags attached.
Fixed in Revision41545.
Attached Files



2019-02-27 20:36


solution_base64.diff (355 bytes)   
Index: src/base64.pp
--- src/base64.pp	(revision 41518)
+++ src/base64.pp	(working copy)
@@ -425,6 +425,8 @@
   Outstream : TStringStream;
   Decoder   : TBase64DecodingStream;
+  if Length(s)=0 then
+    Exit('');
   while Length(Sd) mod 4 > 0 do 
     SD := SD + '=';
solution_base64.diff (355 bytes)   

Michael Van Canneyt

2019-03-02 10:21

administrator   ~0114550

You are right, this is more consistent. Thanks for the patch!

Issue History

Date Modified Username Field Change
2019-02-27 20:36 Doyenne New Issue
2019-02-27 20:36 Doyenne File Added: solution_base64.diff
2019-03-02 07:22 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-03-02 07:22 Michael Van Canneyt Status new => assigned
2019-03-02 10:21 Michael Van Canneyt Fixed in Revision => 41545.
2019-03-02 10:21 Michael Van Canneyt Note Added: 0114550
2019-03-02 10:21 Michael Van Canneyt Status assigned => resolved
2019-03-02 10:21 Michael Van Canneyt Fixed in Version => 3.3.1
2019-03-02 10:21 Michael Van Canneyt Resolution open => fixed
2019-03-02 10:21 Michael Van Canneyt Target Version => 3.2.0