|
From: tonim (JIRA) <tr...@fi...> - 2020-07-30 13:26:01
|
Compression buffer too small error thrown
-----------------------------------------
Key: DNET-944
URL: http://tracker.firebirdsql.org/browse/DNET-944
Project: .NET Data provider
Issue Type: Bug
Components: ADO.NET Provider
Affects Versions: vNext
Environment: Firebird.net provider selecting rows, more frequent selecting data containing blobs, for example SELECT * FROM RDB$PROCEDURES on a database width some procedures. You can reproduce the bug easily setting the CompressionBufferSize to 8192 for example
Reporter: tonim
Assignee: Jiri Cincura
Any environment, when selecting Compression=true in Connection string, more common selecting packetsize=32000
A big constant decompression buffer size is defined in FirebirdNetwordStream.
const int CompressionBufferSize = 1 * 1024 * 1024;
Any decompression bigger than this size throws an exception in HandleDecompression function.
I provide a tested fix, the buffer will grow dynamically, depending on the uncompressed size.
// There is no need to define a big buffer size, it will grow as needed
const int CompressionBufferSize = 32000;
int HandleDecompression(byte[] buffer, int count)
{
_decompressor.OutputBuffer = _compressionBuffer;
_decompressor.InputBuffer = buffer;
_decompressor.NextOut = 0;
_decompressor.NextIn = 0;
_decompressor.AvailableBytesIn = count;
do
{
// Double the buffer size until the decompression fits in the output buffer
_decompressor.OutputBuffer = _compressionBuffer;
_decompressor.AvailableBytesOut = _compressionBuffer.Length - _decompressor.NextOut;
var rc = _decompressor.Inflate(Ionic.Zlib.FlushType.None);
if (rc != Ionic.Zlib.ZlibConstants.Z_OK)
throw new IOException($"Error '{rc}' while decompressing the data.");
if (_decompressor.AvailableBytesIn != 0)
{
byte[] newCompressionBuffer = new byte[_compressionBuffer.Length * 2];
Array.Copy(_compressionBuffer, newCompressionBuffer, _decompressor.NextOut);
_compressionBuffer = newCompressionBuffer;
}
} while (_decompressor.AvailableBytesIn != 0);
return _decompressor.NextOut;
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://tracker.firebirdsql.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
|