cfriedt commented on a change in pull request #2007:
URL: https://github.com/apache/thrift/pull/2007#discussion_r443396568



##########
File path: lib/cpp/src/thrift/transport/TBufferTransports.h
##########
@@ -587,11 +587,9 @@ class TMemoryBuffer : public 
TVirtualTransport<TMemoryBuffer, TBufferBase> {
   void resetBuffer() {
     rBase_ = buffer_;
     rBound_ = buffer_;
-    wBase_ = buffer_;
-    // It isn't safe to write into a buffer we don't own.
-    if (!owner_) {
-      wBound_ = wBase_;
-      bufferSize_ = 0;
+    if (owner_) {
+      wBase_ = buffer_;
+      wBound_ = buffer_ + bufferSize_;

Review comment:
       If the buffer is not owned (read-only), wbase is initialized to buffer + 
wpos (the end of the buffer) and never updated, along with wbound. Throughout 
the lifetime of the buffer, if it is not owned (read-only), wbase == wbound 
meaning there is no space to write. Only if the buffer is owned (writeable) 
should wbase and wbound be reset to the beginning / end of the buffer.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to