Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bzip2 compression broken with Delphi 11 #19

Closed
MPannier opened this issue Feb 14, 2022 · 4 comments
Closed

Bzip2 compression broken with Delphi 11 #19

MPannier opened this issue Feb 14, 2022 · 4 comments

Comments

@MPannier
Copy link

Hello,

the following code will raise an exception "EBZCompressionError" in "TBZCompressionStream.Seek" if compiled with Delphi 11:

procedure TForm1.Button1Click(Sender: TObject);
var
Source: TMemoryStream;
CompressionStream: TStream;
Dest: TMemoryStream;
begin
Source := TMemoryStream.Create;
try
Source.LoadFromFile('C:\temp\temp.txt');
Dest := TMemoryStream.Create;
try
CompressionStream := TBZCompressionStream.Create(bs1, dest);
try
CompressionStream.CopyFrom(Source, 0);
finally
CompressionStream.Free;
end;
finally
Dest.Free;
end;
finally
Source.Free;
end;
end;

In Delphi 11 TStream.CopyFrom has changed a lot. I think this is the reason for the error.

@romankassebaum
Copy link
Contributor

I can reproduce the issue. It is only an exception that occurs inside the IDE. You can ignore it. Here is a code snippet from System.Classes:

function TStream.CopyFrom(const Source: TStream; Count: Int64; BufferSize: Integer): Int64;
...
try
...
except
// If Size/Position is not supported, or no NewSize space is available, or reallocation
// is not supported, or stream is read-only, then ignore exception and let WriteBuffer
// raise exception. Expectable exception classes are: EStreamError, EOSError, EOutOfMemory.
end;

@MPannier
Copy link
Author

MPannier commented Mar 9, 2022

Thanks for the reply. You are right. In my demo application, it works as you described. The exception will only be "visible" in the debugger and the zipped stream can be unzipped without problems.

But I migrate an older project to Delphi 11 and there I will get the exception message "Invalid stream operation" from "TBZCompressionStream.Seek" without debugger. I can click OK and the compression will continue. The zipped stream is also correct and can be unzipped. But I get the exception message. I have checked ccompiler settings and can't find the one which causes the dialog to pop up. Any hints? Did you plan to rewrite the TBZCompressionStream class in future?

@romankassebaum
Copy link
Contributor

I have no idea what causes the exception in your program. Try to debug it.

I have not written this component and also do not plan to rewrite it.

@bah111
Copy link

bah111 commented Mar 29, 2022

This probably has been fixed in D11.1 release. EMB put a size check in the TStream.CopyFrom in D11, which for compressed streams is sometimes pointless. They have done a fix and hence your problems might/should go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants