mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-05-25 06:27:42 +02:00
Fix zbuffer write of empty string
When a zlib stream has avail_in == 0, it will deflate with a Z_BUF_ERROR to indicate that "no progress is possible". A zbuffer write with an empty string will trigger this condition, and the write call returns/raises an error/exception. The fix is simple: change the do/while to a while loop, so that it only tries to deflate if there is actually data to deflate.
This commit is contained in:
parent
32c42d2f4c
commit
addf52e9f0
@ -131,7 +131,7 @@ int msgpack_zbuffer_write(void* data, const char* buf, size_t len)
|
|||||||
zbuf->stream.next_in = (Bytef*)buf;
|
zbuf->stream.next_in = (Bytef*)buf;
|
||||||
zbuf->stream.avail_in = len;
|
zbuf->stream.avail_in = len;
|
||||||
|
|
||||||
do {
|
while(zbuf->stream.avail_in > 0) {
|
||||||
if(zbuf->stream.avail_out < MSGPACK_ZBUFFER_RESERVE_SIZE) {
|
if(zbuf->stream.avail_out < MSGPACK_ZBUFFER_RESERVE_SIZE) {
|
||||||
if(!msgpack_zbuffer_expand(zbuf)) {
|
if(!msgpack_zbuffer_expand(zbuf)) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -141,7 +141,7 @@ int msgpack_zbuffer_write(void* data, const char* buf, size_t len)
|
|||||||
if(deflate(&zbuf->stream, Z_NO_FLUSH) != Z_OK) {
|
if(deflate(&zbuf->stream, Z_NO_FLUSH) != Z_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} while(zbuf->stream.avail_in > 0);
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public:
|
|||||||
m_stream.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(buf));
|
m_stream.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(buf));
|
||||||
m_stream.avail_in = len;
|
m_stream.avail_in = len;
|
||||||
|
|
||||||
do {
|
while(m_stream.avail_in > 0) {
|
||||||
if(m_stream.avail_out < MSGPACK_ZBUFFER_RESERVE_SIZE) {
|
if(m_stream.avail_out < MSGPACK_ZBUFFER_RESERVE_SIZE) {
|
||||||
if(!expand()) {
|
if(!expand()) {
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
@ -75,7 +75,7 @@ public:
|
|||||||
if(deflate(&m_stream, Z_NO_FLUSH) != Z_OK) {
|
if(deflate(&m_stream, Z_NO_FLUSH) != Z_OK) {
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
}
|
}
|
||||||
} while(m_stream.avail_in > 0);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char* flush()
|
char* flush()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user