Skip to content

Commit dff2f3e

Browse files
committed
Fix export of compressed reports larger than UINT_MAX
Signed-off-by: Maxime Gervais <gervais.maxime@gmail.com>
1 parent 763d4d2 commit dff2f3e

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

Source/Core/FileInformation.cpp

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,29 +1352,46 @@ void FileInformation::Export_XmlGz (const QString &ExportFileName, const activef
13521352
}
13531353
else
13541354
{
1355-
char* Buffer=new char[Buffer_Size];
13561355
z_stream strm;
1357-
strm.next_in = (Bytef *) Data.c_str();
1358-
strm.avail_in = Data.size() ;
1359-
strm.total_out = 0;
1360-
strm.zalloc = Z_NULL;
1361-
strm.zfree = Z_NULL;
1362-
if (deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 + 16, 8, Z_DEFAULT_STRATEGY)>=0) // 15 + 16 are magic values for gzip
1356+
memset(&strm, 0, sizeof(strm));
1357+
if (deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 + 16, 8, Z_DEFAULT_STRATEGY) >= 0) // 15 + 16 are magic values for gzip
13631358
{
1359+
char* Buffer = new char[Buffer_Size];
1360+
size_t Data_Size = Data.size();
1361+
size_t Data_Offset = 0;
1362+
bool Error = false;
13641363
do
13651364
{
1366-
strm.next_out = (unsigned char*) Buffer;
1367-
strm.avail_out = Buffer_Size;
1368-
if (deflate(&strm, Z_FINISH)<0)
1365+
uint32_t Chunk_Size = (uint32_t)std::min<size_t>(Buffer_Size * 1024, Data_Size - Data_Offset);
1366+
int flush = (Data_Offset + Chunk_Size >= Data_Size) ? Z_FINISH : Z_NO_FLUSH;
1367+
strm.next_in = (Bytef*)Data.data() + Data_Offset;
1368+
strm.avail_in = Chunk_Size;
1369+
do
1370+
{
1371+
strm.next_out = (Bytef*)Buffer;
1372+
strm.avail_out = Buffer_Size;
1373+
if (deflate(&strm, flush) < 0)
1374+
{
1375+
Error = true;
1376+
break;
1377+
}
1378+
1379+
file->write(Buffer, Buffer_Size - strm.avail_out);
1380+
1381+
Q_EMIT statsFileGenerationProgress(Data_Offset + (strm.next_in - ((Bytef*)Data.data() + Data_Offset)), Data_Size);
1382+
}
1383+
while (strm.avail_out == 0);
1384+
1385+
if (Error)
13691386
break;
1370-
file->write(Buffer, Buffer_Size-strm.avail_out);
13711387

1372-
Q_EMIT statsFileGenerationProgress((char*) strm.next_in - Data.c_str(), Data.size());
1388+
Data_Offset += Chunk_Size;
13731389
}
1374-
while (strm.avail_out == 0);
1375-
deflateEnd (&strm);
1390+
while (Data_Offset < Data_Size);
1391+
1392+
deflateEnd(&strm);
1393+
delete[] Buffer;
13761394
}
1377-
delete[] Buffer;
13781395
}
13791396

13801397
file->flush();

0 commit comments

Comments
 (0)