#1 2021-04-01 09:37:17

tbo
Member
Registered: 2015-04-20
Posts: 349

Error in mORMot2 TZipWrite.WriteRawHeader

mORMot2 (Version 2021/03/29), Windows 10, Delphi 10.4.2, 32 Bit

I used the TSynDaemon class with the following settings:

Settings.LogClass.Family.OnArchive := EventArchiveZip;
Settings.LogClass.Family.ArchiveAfterDays := 1;

First of all, I would like to mention that all files and directories are present and have the correct permissions.

When I exit the server, the process crashes. The following procedure will take place:

- TZipWrite.CreateFrom() is called. aFileName: ...\log\202103.zip 
- TZipWrite.AddDeflated() with the first file is called. aFileName: ...\LogFile\S01\Server_20210330_122816.log
- TZipWrite.WriteHeader() with zipName: Server_20210330_122816.log
- TZipWrite.WriteRawHeader. It crashes when executing fDest.WriteBuffer(tmp.buf^, tmp.len);.
  ThreadName="Main", ExceptionMessage="Stream-Schreibfehler", ExceptionName="EWriteError"

With best regards
Thomas

Last edited by tbo (2021-04-01 09:38:06)

Offline

#2 2021-04-01 17:49:07

tbo
Member
Registered: 2015-04-20
Posts: 349

Re: Error in mORMot2 TZipWrite.WriteRawHeader

The error has the following cause. In the function EventArchiveZip() TZipWrite.CreateFrom() is called. The function TZipWrite.CreateFrom() contains the following source code:

constructor TZipWrite.CreateFrom(
  const aFileName, LastZipNameToIgnore: TFileName);
...
begin
  h := FileOpen(aFileName, fmOpenReadWrite or fmShareDenyNone);
  if not ValidHandle(h) then
  begin
    R := nil;
    h := 0;
  end
  else
    R := TZipRead.Create(h);

  Create(h, aFileName);
...

If the zip file does not exist, no valid handle is returned by the FileOpen() function. When calling the constructor Create(h, aFileName) with an invalid handle, no FileStream is created. Attempting to write to a non-existent stream in TZipWrite.WriteRawHeader() with fDest.WriteBuffer results in a disaster.

With best regards
Thomas

Last edited by tbo (2021-04-01 17:51:46)

Offline

#3 2021-04-01 18:03:25

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,548
Website

Re: Error in mORMot2 TZipWrite.WriteRawHeader

Offline

#4 2021-04-01 18:25:36

tbo
Member
Registered: 2015-04-20
Posts: 349

Re: Error in mORMot2 TZipWrite.WriteRawHeader

Compiler error with function FileCreate()

constructor TZipWrite.CreateFrom(
  const aFileName, LastZipNameToIgnore: TFileName);
...  
    h := FileCreate(aFileName, fmOpenReadWrite or fmShareDenyNone);

In file mormot.core.os.windows.inc the function has the following format:

function FileCreate(const aFileName: TFileName): THandle;

With best regards
Thomas

Offline

#5 2021-04-01 21:41:26

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,548
Website

Re: Error in mORMot2 TZipWrite.WriteRawHeader

Yes it was working on FPC but I didn't test on Delphi.

Will do tomorrow.

Offline

Board footer

Powered by FluxBB