| 248 | } |
| 249 | |
| 250 | void test_invalid_checksum(const boost::shared_array<uint8_t> buf, uint32_t buf_len) { |
| 251 | // Verify checksum checking. |
| 252 | shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer()); |
| 253 | shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf)); |
| 254 | zlib_trans->write(buf.get(), buf_len); |
| 255 | zlib_trans->finish(); |
| 256 | string tmp_buf; |
| 257 | membuf->appendBufferToString(tmp_buf); |
| 258 | // Modify a byte at the end of the buffer (part of the checksum). |
| 259 | // On rare occasions, modifying a byte in the middle of the buffer |
| 260 | // isn't caught by the checksum. |
| 261 | // |
| 262 | // (This happens especially often for the uniform buffer. The |
| 263 | // re-inflated data is correct, however. I suspect in this case that |
| 264 | // we're more likely to modify bytes that are part of zlib metadata |
| 265 | // instead of the actual compressed data.) |
| 266 | // |
| 267 | // I've also seen some failure scenarios where a checksum failure isn't |
| 268 | // reported, but zlib keeps trying to decode past the end of the data. |
| 269 | // (When this occurs, verifyChecksum() throws an exception indicating |
| 270 | // that the end of the data hasn't been reached.) I haven't seen this |
| 271 | // error when only modifying checksum bytes. |
| 272 | int index = static_cast<int>(tmp_buf.size() - 1); |
| 273 | tmp_buf[index]++; |
| 274 | membuf->resetBuffer(const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(tmp_buf.data())), |
| 275 | static_cast<uint32_t>(tmp_buf.length())); |
| 276 | |
| 277 | boost::shared_array<uint8_t> mirror(new uint8_t[buf_len]); |
| 278 | try { |
| 279 | zlib_trans->readAll(mirror.get(), buf_len); |
| 280 | zlib_trans->verifyChecksum(); |
| 281 | BOOST_ERROR("verifyChecksum() did not report an error"); |
| 282 | } catch (TZlibTransportException& ex) { |
| 283 | BOOST_CHECK_EQUAL(ex.getType(), TTransportException::INTERNAL_ERROR); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | void test_write_after_flush(const boost::shared_array<uint8_t> buf, uint32_t buf_len) { |
| 288 | // write some data |
nothing calls this directly
no test coverage detected