diff options
-rw-r--r-- | protocols/Facebook/src/mqtt.cpp | 14 | ||||
-rw-r--r-- | protocols/Facebook/src/server.cpp | 14 |
2 files changed, 17 insertions, 11 deletions
diff --git a/protocols/Facebook/src/mqtt.cpp b/protocols/Facebook/src/mqtt.cpp index 21e4e6001e..837bdd359d 100644 --- a/protocols/Facebook/src/mqtt.cpp +++ b/protocols/Facebook/src/mqtt.cpp @@ -49,11 +49,19 @@ uint8_t *FacebookProto::doUnzip(size_t cbData, const void *pData, size_t &cbRes) zStreamOut.next_in = (uint8_t *)pData; zStreamOut.avail_out = (unsigned)dataSize; zStreamOut.next_out = (uint8_t *)pRes; - inflate(&zStreamOut, Z_FINISH); + int rc = inflate(&zStreamOut, Z_FINISH); inflateEnd(&zStreamOut); - cbRes = dataSize - zStreamOut.avail_out; - return pRes; + switch (rc) { + case Z_OK: + case Z_STREAM_END: + cbRes = dataSize - zStreamOut.avail_out; + return pRes; + } + + mir_free(pRes); + cbRes = 0; + return nullptr; } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/Facebook/src/server.cpp b/protocols/Facebook/src/server.cpp index 8c7a8d7280..013993c741 100644 --- a/protocols/Facebook/src/server.cpp +++ b/protocols/Facebook/src/server.cpp @@ -447,14 +447,12 @@ void FacebookProto::OnPublish(const char *topic, const uint8_t *p, size_t cbLen) // that might be a zipped buffer if (cbLen >= 2) { - if ((((p[0] << 8) | p[1]) % 31) == 0 && (p[0] & 0x0F) == 8) { // zip header ok - size_t dataSize; - void *pData = doUnzip(cbLen, p, dataSize); - if (pData != nullptr) { - debugLogA("UNZIP: <%s>", CMStringA((const char *)pData, (int)dataSize).c_str()); - rdr.reset(dataSize, pData); - mir_free(pData); - } + size_t dataSize; + void *pData = doUnzip(cbLen, p, dataSize); + if (pData != nullptr) { + debugLogA("UNZIP: %d bytes unzipped ok", dataSize); + rdr.reset(dataSize, pData); + mir_free(pData); } } |