Archived Forum Post

Index of archived forum posts

Question:

Problem inflating an empty string in Delphi DLL Crypt2

Feb 05 '13 at 17:57

Firstly let me thank you for the new Chilkat Delphi DLL. This resolves so many ActiveX problems and is greatly appreciated.

However I am having a problem with the CkCrypt2__inflateStringENC function, when inflating compressed text that should result in an empty string.

The wrapper function I am using is this...

function TChilkatDLL_SymmetricEncryption.uncompressText_wide(const aCompressedText: WideString; out aoutPlainText: WideString): Boolean;
var
  plainText_wide_ptr: PWideChar;
begin
  aoutPlainText := '';

  plainText_wide_ptr := CkCrypt2__inflateStringENC(fCryptObjectHandle, PWideChar(aCompressedText));

  if (plainText_wide_ptr = nil) then begin
    raise Exception.Create('InflateStringENC failed: ' + getLastErrorMessageFromDLL);
  end
  else begin
    aoutPlainText := plainText_wide_ptr;

    result := True;
  end;
end;

Note: I am using Delphi 2007, so I am explicitly using WideString types, rather than just String types as they would be in Delphi XE2.

The Charset is set to 'ANSI', the EncodingMode is set to 'base64', and the CompressionAlgorithm is set to 'bzip2'.

This function has been tested and exercised extensively, and seems to work completely reliably, except in one specific case - when the expected result is an empty string.

Here is the lastErrorText from the function call...

ChilkatLog:
  InflateStringENC:
    DllDate: Dec 13 2012
    UnlockPrefix: SENETCCrypt
    Username: NEVILLE-WIN7:Neville
    Architecture: Little Endian; 32-bit
    Language: C++ Builder XE2
    VerboseLogging: 0
  --InflateStringENC
--ChilkatLog

In this case, the aCompressedText is '4aeUswAAAAA=', and the result of the CkCrypt2__inflateStringENC function call is usually (but not always) pointing to garbage data. (Sometimes the result is an empty string, but this is not reliable.)

We have had to work around the problem like this...

function TChilkatDLL_SymmetricEncryption.uncompressText_wide(const aCompressedText: WideString; out aoutPlainText: WideString): Boolean;
var
  plainText_wide_ptr: PWideChar;
begin
  aoutPlainText := '';

  if (aCompressedText = '4aeUswAAAAA=') then begin
    aoutPlainText := '';

    result := True;
  end
  else begin
    plainText_wide_ptr := CkCrypt2__inflateStringENC(fCryptObjectHandle, PWideChar(aCompressedText));

    if (plainText_wide_ptr = nil) then begin
      raise Exception.Create('InflateStringENC failed: ' + getLastErrorMessageFromDLL);
    end
    else begin
      aoutPlainText := plainText_wide_ptr;

      result := True;
    end;
  end;    
end;

This work around has been reasonably well tested, and we have not yet seen it fail. But it is specific to our situation, and is not a full or general purpose solution to the problem.

All the diagnosis we have been able to perform has come to the conclusion that the problem is occurring in the DLL CkCrypt2__inflateStringENC function.

Could you please either verify our findings, or point out where we may have gone wrong.


Accepted Answer

Please try this new build:
http://www.chilkatsoft.com/preRelease/chilkat-9.4.1-delphi.zip


Answer

I found and fixed the problem. I'll post a download to a new build as soon as possible.