Home > Back-end >  XE 10.2.3 ZLib library may exist serious bugs
XE 10.2.3 ZLib library may exist serious bugs

Time:11-14

Years no Posting, special remind DELPHI users pay attention to this problem,

In the call System. ZLib. ZDecompressStream, in some cases may be in infinite loop, unable to quit,

 
Procedure ZDecompressStream (inStream outStream: TStream);
Const
BufferSize=32768;
Var
Zstream: TZStreamRec;
Zresult: Integer;
InBuffer: TBytes;
OutBuffer: TBytes;
InSize: Integer;
OutSize: Integer;
The begin
SetLength (inBuffer, BufferSize);
SetLength (outBuffer, BufferSize);
FillChar (zstream, SizeOf (TZStreamRec), 0).

ZDecompressCheck (InflateInit (zstream));

Try
InSize:=inStream. Read (inBuffer, bufferSize);
While inSize & gt; 0 do
The begin
Zstream. Next_in:=@ inBuffer [0].
Zstream. Avail_in:=inSize;

Repeat
Zstream. Next_out:=@ outBuffer [0].
Zstream. Avail_out:=bufferSize;

ZDecompressCheckWithoutBufferError (inflate (zstream Z_NO_FLUSH));

OutSize:=bufferSize - zstream. Avail_out;

OutStream. Write (outBuffer, outSize);
Until (zstream. Avail_in=0) and (zstream. Avail_out & gt; 0);

InSize:=inStream. Read (inBuffer, bufferSize);
end;

Repeat
Zstream. Next_out:=@ outBuffer [0].
Zstream. Avail_out:=bufferSize;

Zresult:=ZDecompressCheckWithoutBufferError (inflate (zstream Z_FINISH)); <-- -- -- -- -- -- -- -- -- -- -- -- -- --

OutSize:=bufferSize - zstream. Avail_out;

OutStream. Write (outBuffer, outSize);
Until (zresult=Z_STREAM_END) and (zstream avail_out & gt; 0);
The finally
ZDecompressCheck (inflateEnd (zstream));
end;
end;



 
The function ZDecompressCheckWithoutBufferError (code: Integer) : Integer; The phrase ";
The begin
Result:=code;

If code & lt; 0 then
If (code & lt;> Z_BUF_ERROR) then & lt; -- -- -- -- -- -- -- -- -- -- -- --
the culpritRaise EZDecompressionError. Create (string (_z_errmsg [2 - code]));
end;



Why is unclear XE 10.2.3 ZLib code in code=Z_BUF_ERROR, don't throw an exception,

The consequences is always infinite loop in the repeat,

CodePudding user response:

Then look at DELPHI 2010 ZLib library, completely OK

 
Procedure ZDecompressStream (inStream outStream: TStream);
Const
BufferSize=32768;
Var
Zstream: TZStreamRec;
Zresult: Integer;
InBuffer: array [0.. bufferSize - 1] of AnsiChar;
OutBuffer: array [0.. bufferSize - 1] of AnsiChar;
InSize: Integer;
OutSize: Integer;
The begin
FillChar (zstream, SizeOf (TZStreamRec), 0).

ZCompressCheck (InflateInit (zstream));

InSize:=inStream. Read (inBuffer, bufferSize);

While inSize & gt; 0 do
The begin
Zstream. Next_in:=inBuffer;
Zstream. Avail_in:=inSize;

Repeat
Zstream. Next_out:=outBuffer;
Zstream. Avail_out:=bufferSize;

ZCompressCheck (inflate (zstream Z_NO_FLUSH));

//outSize:=zstream next_out - outBuffer;
OutSize:=bufferSize - zstream. Avail_out;

OutStream. Write (outBuffer, outSize);
Until (zstream. Avail_in=0) and (zstream. Avail_out & gt; 0);

InSize:=inStream. Read (inBuffer, bufferSize);
end;

Repeat
Zstream. Next_out:=outBuffer;
Zstream. Avail_out:=bufferSize;

Zresult:=ZCompressCheck (inflate (zstream Z_FINISH));

//outSize:=zstream next_out - outBuffer;
OutSize:=bufferSize - zstream. Avail_out;

OutStream. Write (outBuffer, outSize);
Until (zresult=Z_STREAM_END) and (zstream avail_out & gt; 0);

ZCompressCheck (inflateEnd (zstream));
end;



 
The function ZCompressCheck (code: Integer) : Integer;
The begin
Result:=code;

If code & lt; 0 then
The begin
Raise EZCompressionError. Create (_z_errmsg [2 - code]);
end;
end;

The function ZDecompressCheck (code: Integer) : Integer;
The begin
Result:=code;

If code & lt; 0 then
The begin
Raise EZDecompressionError. Create (_z_errmsg [2 - code]);
end;
end;

CodePudding user response:

Also welcome you stick a different version of the DELPHI ZLib function code, see which version may be the problem,

CodePudding user response:

10.2.3 compile time warning information? There may be some function changed for cross-platform, didn't test,

CodePudding user response:

If (code & lt;> Z_BUF_ERROR) then & lt; -- -- -- -- -- -- -- -- -- -- -- --
the culpritRaise EZDecompressionError. Create (string (_z_errmsg [2 - code]));

The above should be if code=Z_BUF_ERROR) then
Raise EZDecompressionError. Create (string (_z_errmsg [2 - code]));
logically

CodePudding user response:

Z_BUF_ERROR is just a warning, not an error, mean the decompression after the size of the block of data more than the size of the buffer, but the decompression can also normal,
Your question is estimated to be caused by other reasons,

CodePudding user response:

reference 5 floor BlueStorm reply:
Z_BUF_ERROR just a warning, not an error, mean after unzip the size of the block of data more than the size of the buffer, but the decompression can also normal,
Your question is estimated to be caused by other reasons,


This estimate is a bit you mean ah, my file is damaged, but can't have been in infinite loop does not come out,nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related