Zeoslib 6.6.2-RC: Reproducable bug. Truncate fields.
Posted: 12.01.2008, 00:27
Project demonstrating this bug is at http://zeosbugs.firmos.at/view.php?id=86
Delphi 2007 update 3 with Firebird 2.0.3 on Windows XP.
Result of running TForm1.ButtonInsertClick():
Step 2. Create a table with char(20) field named "hash".
Step 3. Convert this hex string to a 20-byte binary string and insert:
'4142434445464748494A4B4C4D4E4F505152110F'
This is chars 'A' to 'R' and last 2 chars is decimal #17 + #15.
Step 4. Disconnect from database and reconnect.
Step 5. ZQuery.FieldByName('hash').AsString is truncated to 18 chars.
TForm1.ButtonInsertClick():
TForm1.ButtonQueryClick():
HexUtils.StringToHex() -- renamed function from OpenStrSecII open source project
I'm in the middle of emergency so I hope this is enough info, just in case I'm unable to upload sample project this weekend and file bug report.
Delphi 2007 update 3 with Firebird 2.0.3 on Windows XP.
Result of running TForm1.ButtonInsertClick():
Result of running TForm1.ButtonQueryClick() -- after disconnecting/reconnecting firstInserting id = "313067062 hash = "ABCDEFGHIJKLMNOPQR"
Length(hash) = 20
Inserted.
Step 1. Create a database.Result: id = "313067062" hash = "ABCDEFGHIJKLMNOPQR"
Length(hash) = 18
Step 2. Create a table with char(20) field named "hash".
Step 3. Convert this hex string to a 20-byte binary string and insert:
'4142434445464748494A4B4C4D4E4F505152110F'
This is chars 'A' to 'R' and last 2 chars is decimal #17 + #15.
Step 4. Disconnect from database and reconnect.
Step 5. ZQuery.FieldByName('hash').AsString is truncated to 18 chars.
TForm1.ButtonInsertClick():
Code: Select all
procedure TForm1.ButtonInsertClick(Sender: TObject);
var
hash : AnsiString;
id : Integer;
begin
//this part works fine and data is properly saved.
id := GetTickCount();
hash := HexUtils.HexToString('4142434445464748494A4B4C4D4E4F505152110F');
Form1.MemoLog.Lines.Add('Inserting id = "'+IntToStr(id)+
' hash = "'+ hash +'"');
Form1.MemoLog.Lines.Add('Length(hash) = '+IntToStr(Length(hash)));
DataModule1.ZQuery1.Append;
DataModule1.ZQuery1.FieldByName('id').Value := id;
DataModule1.ZQuery1.FieldByName('hash').Value := hash;
DataModule1.ZQuery1.Post;
MemoLog.Lines.Add('Inserted.');
end;
Code: Select all
procedure TForm1.ButtonQueryClick(Sender: TObject);
var
hash: AnsiString;
id: Integer;
begin
//IMPORTANT: disconnect/reconnect before running this to show bug
id := DataModule1.ZQuery1.FieldByName('id').AsInteger;
hash := DataModule1.ZQuery1.FieldByName('hash').AsString;
Form1.MemoLog.Lines.Add('Result: id = "' + IntToStr(id) + '"' +
' hash = "' + hash + '"');
Form1.MemoLog.Lines.Add('Length(hash) = ' + IntToStr(Length(hash)));
end;
Code: Select all
//Copied from OpenStrSecII Project - ASN1.PAS file
function HexToString(const HexStr: string): AnsiString;
const
Digits = '0123456789ABCDEF';
var
I, J, K, P: Integer;
B: Byte;
U: string;
begin
SetLength(Result,Length(HexStr) shr 1);
J := 1;
B := 0;
K := 0;
U := UpperCase(HexStr);
for I := 1 to Length(U) do begin
P := Pos(U[I],Digits);
if P > 0 then begin
B := (B shl 4) + P - 1;
Inc(K);
end;
if K = 2 then begin
Result[J] := Char(B);
Inc(J);
B := 0;
K := 0;
end;
end;
SetLength(Result,J-1);
end;