MCPcopy Create free account
hub / github.com/apache/thrift / test_invalid_checksum

Function test_invalid_checksum

lib/cpp/test/ZlibTest.cpp:250–285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

248}
249
250void 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
287void test_write_after_flush(const boost::shared_array<uint8_t> buf, uint32_t buf_len) {
288 // write some data

Callers

nothing calls this directly

Calls 11

appendBufferToStringMethod · 0.80
resetBufferMethod · 0.80
dataMethod · 0.80
verifyChecksumMethod · 0.80
writeMethod · 0.65
lengthMethod · 0.65
getMethod · 0.45
finishMethod · 0.45
sizeMethod · 0.45
readAllMethod · 0.45
getTypeMethod · 0.45

Tested by

no test coverage detected