Corrupted large objects after update

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
gside
Posts: 9
Joined: Mon 02 Dec 2019 17:22

Corrupted large objects after update

Post by gside » Tue 03 May 2022 07:57

Hello,

When I update an existing large object, with a large object smaller than the currently stored one, the written data is corrupted by trailing data, because the previous large object size is not updated (the large object is not truncated to the new size).
For example, I store a large object 1000 bytes long. Then I update data for this same large object, with a content of 900 bytes. The stored data is corrupted because its lenght is still 1000 bytes: The last 100 bytes were not truncated.

I tried multiple ways to store the updated large object, but everything fails with the same result.
Tried using directly TPgLargeObject, then by using a TPgTable and a TPgLargeObjectField, tried with ou without large object caching.

Here is a code sample used to write the large object:

Code: Select all

    pgConnection.StartTransaction;
    ms.LoadFromFile(FilePath);
    lobj := TPgLargeObject.Create(pgConnection);
    lobj.Cached := False; // Setting it to true wont resolve the issue
    lobj.OID := OID; // For this example, we assume that the large object already exist
    lobj.ReadBlob;
    lobj.Clear; // With cached=False, the size is not reset to 0 here. I also tried Truncate(0)
    ms.Position := 0;
    lobj.LoadFromStream(ms); // The large object size is not set to the ms size
    lobj.WriteBlob; // Here, the large object seems to be written on top of the previous object, without truncating data to the new size
    lobj.CloseObject;
    pgConnection.Commit;
I directly checked the size on postgres, so the ReadBlob is not part of the problem.

Using PgDAC version 6.3.2 and Delphi 10.3 update 2

I need a workaround for a commercial product
Thank you

evgeniym
Devart Team
Posts: 85
Joined: Thu 13 May 2021 07:08

Re: Corrupted large objects after update

Post by evgeniym » Thu 05 May 2022 11:53

Hi there,

Kindly be informed we were able to reproduce the issue and fixed it.
This fix will be added to the next build of our product and it will be available to all customers. Please note that as a temporary workaround until a new build is released, we can provide you with a PgDAC nightly build that includes this fix.
To create this build for you, please provide us with your license number and the version of the IDE you are interested in.

Regards,
Evgeniy

gside
Posts: 9
Joined: Mon 02 Dec 2019 17:22

Re: Corrupted large objects after update

Post by gside » Fri 06 May 2022 15:07

Hi Evgeniym,
Much appreciated, thank you.
I'll try to send you my licence number and versions through private msg
Regards,

evgeniym
Devart Team
Posts: 85
Joined: Thu 13 May 2021 07:08

Re: Corrupted large objects after update

Post by evgeniym » Mon 09 May 2022 16:16

Hi.
The link was sent in a private message.
Regards,
Evgeniy

gside
Posts: 9
Joined: Mon 02 Dec 2019 17:22

Re: Corrupted large objects after update

Post by gside » Tue 10 May 2022 19:13

Hi,
I received your email but no nightly build, only a message that asks me to renew my licence.
My bad, my understanding was that reporting a major bug that could benefit to all was worth a nightly build ;-)
I have developed a workaround so I guess everything is "ok" now...

evgeniym
Devart Team
Posts: 85
Joined: Thu 13 May 2021 07:08

Re: Corrupted large objects after update

Post by evgeniym » Wed 11 May 2022 11:12

Hi,

I’m glad that your issue is fully resolved now and you can use all the features of our product.
You can download the trial version of night build by this link:
http://download.devart.com/dac/pgdac26(08.05.2022).exe
You can use Truncate(size) to resize the object.

Regards,
Evgeniy

Post Reply