Icon View Incident Report

Serious Serious
Reported By: Mark Pickersgill
Reported On: 9/28/2004
For: Version 4.10 Build 1
# 1849 Blob Reads Will Miss the Last Byte of the Blob If the Blob Read Size Is Not Exact

There's an apparent bug in the TDataCursor.GetBlob function that causes the final byte in a blob to be missed under some circumstances.

The problem occurs under the following two conditions:

1 - The Blob stream is being read in blocks of data < than the blob size.
2 - The Blob size itself is n * SizeOf(buffer)+1. Where the buffer is the block of data that is being used to store the results from the stream's Read function.

The problem code is in dbisamen.pas on line 24278 of DBISAM 3.27 and line 24475 of DBISAM 3.30.

The code extract is:
if (Offset < (TBlobBuffer(BlobHandle).Size-1)) then

Due to the "if" condition, the ActualBytes will not be set if the current offset is one less than the blob size. Hence the last byte will be ignored!

// Quick sample code - needs appropriate table with a MEMO blob type.
// The BLOB should be filled with 1026 or 2051 etc bytes.
  r, i : integer;
  buf : array[0..1024] of byte;
  strm : TStream;
  s : string;
  strm := tbl1.CreateBlobStream(tbl1.FieldByName('XML'), bmRead);
  r := strm.Read(buf, SizeOf(buf));
  while r > 0 do begin
    s := '';
    for i := 0 to r-1 do begin
      s := s + Char(buf[i]);
    Memo1.Lines.Text := Memo1.Lines.Text + s;
    r := strm.Read(buf, SizeOf(buf));

Resolution Resolution
Fixed Problem on 9/28/2004 in version 4.11 build 1