@@ -1343,7 +1343,7 @@ CString str = strText;
1343
1343
1344
1344
void CMUSHclientDoc::ReceiveMsg ()
1345
1345
{
1346
- char buff [1000 ];
1346
+ char buff [1000 ]; // must be less than COMPRESS_BUFFER_LENGTH or it won't fit
1347
1347
int count = m_pSocket->Receive (buff, sizeof (buff) - 1 );
1348
1348
1349
1349
Frame.CheckTimerFallback (); // see if time is up for timers to fire
@@ -1470,7 +1470,30 @@ int count = m_pSocket->Receive (buff, sizeof (buff) - 1);
1470
1470
}
1471
1471
1472
1472
// decompress it
1473
- int iCompressResult = inflate (&m_zCompress, Z_SYNC_FLUSH);
1473
+ int iCompressResult;
1474
+ do {
1475
+ iCompressResult = inflate (&m_zCompress, Z_SYNC_FLUSH);
1476
+
1477
+ // buffer too small? (highly compressed text, huh?)
1478
+ // make larger, try again - version 4.74
1479
+ // See: http://www.gammon.com.au/forum/?id=11160
1480
+ if (iCompressResult == Z_BUF_ERROR)
1481
+ {
1482
+ m_nCompressionOutputBufferSize += COMPRESS_BUFFER_LENGTH;
1483
+ m_zCompress.avail_out += COMPRESS_BUFFER_LENGTH;
1484
+ m_CompressOutput = (Bytef *) realloc (m_CompressOutput, m_nCompressionOutputBufferSize);
1485
+
1486
+ if (m_CompressOutput == NULL )
1487
+ {
1488
+ OnConnectionDisconnect (); // close the world
1489
+ free (m_CompressInput); // may as well get rid of compression input as well
1490
+ m_CompressInput = NULL ;
1491
+ TMessageBox (" Insufficient memory to decompress MCCP text." , MB_ICONEXCLAMATION);
1492
+ return ;
1493
+ } // end of cannot get more memory
1494
+ } // end of Z_BUF_ERROR
1495
+
1496
+ } while (iCompressResult == Z_BUF_ERROR);
1474
1497
1475
1498
if (App.m_iCounterFrequency )
1476
1499
{
@@ -1481,18 +1504,20 @@ int count = m_pSocket->Receive (buff, sizeof (buff) - 1);
1481
1504
// error?
1482
1505
if (iCompressResult < 0 )
1483
1506
{
1507
+ char * pMsg = m_zCompress.msg ; // closing may clear the message
1508
+
1484
1509
OnConnectionDisconnect (); // close the world
1485
- if (m_zCompress. msg )
1510
+ if (pMsg )
1486
1511
UMessageBox (TFormat (" Could not decompress text from MUD: %s" ,
1487
- (LPCTSTR) m_zCompress. msg ), MB_ICONEXCLAMATION);
1512
+ (LPCTSTR) pMsg ), MB_ICONEXCLAMATION);
1488
1513
else
1489
1514
UMessageBox (TFormat (" Could not decompress text from MUD: %i" ,
1490
1515
iCompressResult), MB_ICONEXCLAMATION);
1491
1516
return ;
1492
1517
}
1493
1518
1494
1519
// work out how much we got, and display it
1495
- int iLength = COMPRESS_BUFFER_LENGTH - m_zCompress.avail_out ;
1520
+ int iLength = m_nCompressionOutputBufferSize - m_zCompress.avail_out ;
1496
1521
1497
1522
// stats - count uncompressed bytes
1498
1523
m_nTotalUncompressed += iLength;
@@ -1507,7 +1532,7 @@ int count = m_pSocket->Receive (buff, sizeof (buff) - 1);
1507
1532
1508
1533
DisplayMsg ((LPCTSTR) m_CompressOutput, iLength, 0 ); // send uncompressed data to screen
1509
1534
m_zCompress.next_out = m_CompressOutput; // reset for more output
1510
- m_zCompress.avail_out = COMPRESS_BUFFER_LENGTH ;
1535
+ m_zCompress.avail_out = m_nCompressionOutputBufferSize ;
1511
1536
}
1512
1537
1513
1538
// if end of stream, turn decompression off
@@ -1971,7 +1996,7 @@ CString strLine (lpszText, size);
1971
1996
m_zCompress.next_in = m_CompressInput;
1972
1997
m_zCompress.avail_in = size;
1973
1998
m_zCompress.next_out = m_CompressOutput;
1974
- m_zCompress.avail_out = COMPRESS_BUFFER_LENGTH ;
1999
+ m_zCompress.avail_out = m_nCompressionOutputBufferSize ;
1975
2000
m_nTotalCompressed += size;
1976
2001
return ; // done with this loop, now it needs to be decompressed
1977
2002
}
@@ -1993,7 +2018,7 @@ CString strLine (lpszText, size);
1993
2018
m_zCompress.next_in = m_CompressInput;
1994
2019
m_zCompress.avail_in = size;
1995
2020
m_zCompress.next_out = m_CompressOutput;
1996
- m_zCompress.avail_out = COMPRESS_BUFFER_LENGTH ;
2021
+ m_zCompress.avail_out = m_nCompressionOutputBufferSize ;
1997
2022
m_nTotalCompressed += size;
1998
2023
return ; // done with this loop, now it needs to be decompressed
1999
2024
}
0 commit comments