diff --git a/lib/cpp/src/thrift/transport/THeaderTransport.cpp b/lib/cpp/src/thrift/transport/THeaderTransport.cpp
--- a/lib/cpp/src/thrift/transport/THeaderTransport.cpp
+++ b/lib/cpp/src/thrift/transport/THeaderTransport.cpp
@@ -297,7 +297,12 @@ void THeaderTransport::untransform(uint8_t* ptr, uint32_t sz) {
                                     "Error while zlib deflateEnd");
       }
 
-      memcpy(ptr, tBuf_.get(), sz);
+      // The result lives in tBuf_ and is typically larger than the source
+      // section, so it does not fit back into the receive buffer at ptr.
+      // Use the transform buffer as the receive buffer instead of copying.
+      rBuf_.swap(tBuf_);
+      std::swap(rBufSize_, tBufSize_);
+      ptr = rBuf_.get();
     } else {
       throw TApplicationException(TApplicationException::MISSING_RESULT, "Unknown transform");
     }
