fcl-base/base64.pp: DecodeStringBase64('') raises exception
Original Reporter info from Mantis: Doyenne
-
Reporter name:
Original Reporter info from Mantis: Doyenne
- Reporter name:
Description:
If DecodeStringBase64 is called with an empty string as parameter, it raises an exception.
&LtPos;b>Expected behaviour&LtPos;/b>
I think it should return an empty string, as explained here:
https://stackoverflow.com/questions/15212127/is-an-empty-string-valid-base64-encoded-data-of-zero-bytes-length
In addition, the trunk version of base64.pp has the following code in EncodeStringBase64():
if Length(s)=0 then
Exit('');
Therefore, '' is encoded into '' and as such, '' should be decoded into '' as well.
&LtPos;b>Reason of the exception&LtPos;/b>
DecodeStringBase64() uses the following code:
Outstream.CopyFrom(Decoder,Decoder.Size);
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.
&LtPos;b>Solution&LtPos;/b>
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.
Mantis conversion info:
- Mantis ID: 35161
- Fixed in version: 3.3.1
- Fixed in revision: 41545 (#1c9bca29).
- Target version: 3.2.0