diff options
author | Stijn Buys <ingar@osirion.org> | 2008-05-31 11:43:46 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-05-31 11:43:46 +0000 |
commit | 2a41efa0d43b573e1c8851086268b8a64d51c511 (patch) | |
tree | 1727c8aeb8b540ee4990bd92c0e8158a409b9397 /src/core/netconnection.cc | |
parent | 4b527153ccf2a2830e38038ce4cf06ccc764d310 (diff) |
fixes zlib compression, infi file parser updates
Diffstat (limited to 'src/core/netconnection.cc')
-rw-r--r-- | src/core/netconnection.cc | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc index a0a0497..fc2e5d0 100644 --- a/src/core/netconnection.cc +++ b/src/core/netconnection.cc @@ -164,13 +164,13 @@ void NetConnection::receive() zrecvbuf[received_compressed_size] = *c; received_compressed_size++; - if (received_compressed_size == (size_t) compressed_size) { + if (compressed_size == received_compressed_size) { // uncompress - char zunbuf[BLOCKSIZE]; + char zunbuf[BLOCKSIZE*2]; memset(zunbuf, 0, sizeof(zunbuf)); - unsigned long zunbuf_size = BLOCKSIZE - 1; + uLong zunbuf_size = (uLong) BLOCKSIZE*2 - 1; - int status = uncompress((Bytef *) zunbuf, &zunbuf_size, (Bytef *) zrecvbuf, compressed_size); + int status = uncompress((Bytef *) zunbuf, &zunbuf_size, (Bytef *) zrecvbuf, (uLong) compressed_size); if (status != Z_OK) { con_warn << "zlib error " << status << " uncompressing incoming datablock!\n"; @@ -203,10 +203,14 @@ void NetConnection::receive() receive_compressed = true; received_compressed_size = 0; - compressed_size = *(c+2) + (*(c+3) << 8); + compressed_size = (uLong) (*(unsigned char *)(c+2) + (*(unsigned char *)(c+3) << 8)); c += 3; bytes_received -= 3; memset(zrecvbuf, 0, sizeof(zrecvbuf)); + if (compressed_size > BLOCKSIZE) { + con_warn << "Incoming compressed datablock exceeds " << BLOCKSIZE << " bytes!\n"; + receive_compressed = false; + } } else if (( *c == '\n') || (*c == '\r')) { if (messageblock.size()) { |