Encrypted Fields Access Violation after Update to 9.4.3

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
OlliWW
Posts: 25
Joined: Mon 25 Mar 2013 17:03

Encrypted Fields Access Violation after Update to 9.4.3

Post by OlliWW » Thu 22 Apr 2021 09:39

Hello,

I'm using SDAC 9.4.3 with Delphi 10.4.2

The previous version was: 9.3.1


Since 9.4.3 i get an access violation when i'm selecting encrpyted fields which are null (not filled with data [yet]).

My Code is exact the same as in the documentation. I'm reading the field with "FieldByName"

Code: Select all

MSQuery.SQL.Text := 'SELECT * FROM EMP';

MSQuery.Encryption.Encryptor := MSEncryptor;
MSQuery.Encryption.Fields := 'ENAME, HIREDATE, SAL, FOTO';
MSEncryptor.Password := '11111';

MSQuery.DataTypeMap.AddFieldNameRule ('ENAME', ftString);
MSQuery.DataTypeMap.AddFieldNameRule ('HIREDATE', ftDateTime);
MSQuery.DataTypeMap.AddFieldNameRule ('SAL', ftFloat);

MSQuery.Open;

myStringVar := MSQuery.FieldByName('ENAME').AsString;

When calling "FieldByName" i get an access violation.

Here is the callstack:

Code: Select all

0082d4e7 +003b Project.exe       CRDataTypeMap                  TDataConverters.ExtBytesToAStr
008632ea +00fa Project.exe       CRAccess                       TCRRecordSet.GetFieldData
007cb59f +00c3 Project.exe       MemData                        TData.GetField
00f7d0ce +002e Project.exe       OLEDBAccess                    TOLEDBRecordSet.GetField
007e57db +0083 Project.exe       MemDS                          TMemDataSet.GetFieldData
007e5592 +0016 Project.exe       MemDS                          TMemDataSet.GetFieldData
00799b53 +0027 Project.exe       Data.DB             13131   +2 TDataSet.GetFieldData
007e5613 +0047 Project.exe       MemDS                          TMemDataSet.GetFieldData
007876ab +0057 Project.exe       Data.DB              5149   +9 TField.GetData
00789767 +0013 Project.exe       Data.DB              6142   +1 TStringField.GetValue
0078954a +000a Project.exe       Data.DB              6073   +1 TStringField.GetAsAnsiString
0078950c +0020 Project.exe       Data.DB              6063   +2 TStringField.GetAsString
0172299d +1211 Project.exe       myClass       570 +282 TmyClass.doread

With 9.3.1 the code above works

Stellar
Devart Team
Posts: 496
Joined: Tue 03 Oct 2017 11:00

Re: Encrypted Fields Access Violation after Update to 9.4.3

Post by Stellar » Fri 23 Apr 2021 14:13

Thank you for providing the information. We've fixed several similar issues, please check whether the issue occurs in nightly build of SDAC.
Please send us your license number, and we'll send you the nightly build of SDAC. You can send the license number using the contact form at our site: devart.com/company/contactform.html

OlliWW
Posts: 25
Joined: Mon 25 Mar 2013 17:03

Re: Encrypted Fields Access Violation after Update to 9.4.3

Post by OlliWW » Thu 27 Jan 2022 17:52

This problem also exists in SDAC up to Version 10.0.2.

These errors are currently a show stopper for Delphi 11

Stellar
Devart Team
Posts: 496
Joined: Tue 03 Oct 2017 11:00

Re: Encrypted Fields Access Violation after Update to 9.4.3

Post by Stellar » Mon 31 Jan 2022 09:24

Hi,

Unfortunately, we couldn't reproduce the issue.
To investigate this behavior of SDAC, please compose a small sample demonstrating the issue and send it to us, including database objects creating scripts.
You can send the sample using the contact form at our site: devart.com/company/contactform.html

Best regards,
Sergey

OlliWW
Posts: 25
Joined: Mon 25 Mar 2013 17:03

Re: Encrypted Fields Access Violation after Update to 9.4.3

Post by OlliWW » Thu 03 Feb 2022 00:23

Here is the sample code, tests with SDAC 10.0.2 and SQL Server 2019.

The issue occours if a field is "0x". In SDAC 9.3. and lower the bug does not exists. AsString returns a empty string.
After 9.3. you get an access violation.

I'll send you the code also via email.

Code: Select all

unit Unit3;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, DBAccess, SdacVcl, Data.DB, MSAccess,
  CREncryption;

type
  TForm3 = class(TForm)
    MSConnection1: TMSConnection;
    MSConnectDialog1: TMSConnectDialog;
    MSEncryptor1: TMSEncryptor;
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

const
  cTempTableName = '#EncryptionTemp';

procedure TForm3.FormCreate(Sender: TObject);
var
  qryExec: TMSQuery;
  myStringVar: String;
begin
  MSConnection1.Connect;

  // Create Temp Table
  qryExec := TMSQuery.Create(nil);
  qryExec.Connection := MSConnection1;
  try
    qryExec.SQL.Text :=
      'create table ' + cTempTableName + ' ( ' +
        '_GEN INT IDENTITY(1, 1) primary key , ' +
        '_COL_TEST varbinary(200) NULL ' +
      ')';
    qryExec.Execute;
  finally
    FreeAndNil(qryExec);
  end;


  // Insert "0x" into the VarBinary Field
  qryExec := TMSQuery.Create(nil);
  try
    qryExec.Connection := MSConnection1;
    qryExec.SQL.Text := 'insert into ' + cTempTableName + ' (_COL_TEST) values (CONVERT(varbinary(10),''''))';
    qryExec.Execute;
  finally
    FreeAndNil(qryExec);
  end;

  qryExec := TMSQuery.Create(nil);
  qryExec.Connection := MSConnection1;
  try
    qryExec.SQL.Text := 'SELECT _COL_TEST FROM ' + cTempTableName;

    qryExec.Encryption.Encryptor := MSEncryptor1;
    qryExec.Encryption.Fields := '_COL_TEST';
    MSEncryptor1.Password := '11111';

    qryExec.DataTypeMap.AddFieldNameRule ('_COL_TEST', ftString);

    qryExec.Open;

    // Set Breakpoint here. The "AsString" Function results in a access violation
    myStringVar := qryExec.FieldByName('_COL_TEST').AsString;
  finally
    FreeAndNil(qryExec);
  end;


  // Drop Temp Table
  qryExec := TMSQuery.Create(nil);
  qryExec.Connection := MSConnection1;
  try
    qryExec.SQL.Text := 'drop table ' + cTempTableName;
    qryExec.Execute;
  finally
    FreeAndNil(qryExec);
  end;
end;

end.

pavelpd
Devart Team
Posts: 109
Joined: Thu 06 Jan 2022 14:16

Re: Encrypted Fields Access Violation after Update to 9.4.3

Post by pavelpd » Fri 04 Feb 2022 15:04

Hi
Thank you for contacting us! Hope you are doing well!

With the information, you sent us we were able to reproduce the error and now we will investigate its origin.

We will inform you about the results shortly.

Please, let me know if you have any other questions.

Post Reply