You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2015/02/15 19:26:40 UTC
thrift git commit: THRIFT-2937 Allow setting a maximum frame size
Repository: thrift
Updated Branches:
refs/heads/master 283899bf9 -> 0d964d8e5
THRIFT-2937 Allow setting a maximum frame size
Set maximum frame size to 256MB (same as TNonblockingServer)
Client: cpp
Patch: Cristian Klein & Roger Meier
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/0d964d8e
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/0d964d8e
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/0d964d8e
Branch: refs/heads/master
Commit: 0d964d8e520067c461f9dcef9f7654d43c8fba7f
Parents: 283899b
Author: Roger Meier <ro...@apache.org>
Authored: Sun Feb 15 19:24:50 2015 +0100
Committer: Roger Meier <ro...@apache.org>
Committed: Sun Feb 15 19:24:50 2015 +0100
----------------------------------------------------------------------
lib/cpp/src/thrift/transport/TBufferTransports.cpp | 5 +++++
lib/cpp/src/thrift/transport/TBufferTransports.h | 12 ++++++++++++
2 files changed, 17 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/0d964d8e/lib/cpp/src/thrift/transport/TBufferTransports.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TBufferTransports.cpp b/lib/cpp/src/thrift/transport/TBufferTransports.cpp
index bedb5a5..62737af 100644
--- a/lib/cpp/src/thrift/transport/TBufferTransports.cpp
+++ b/lib/cpp/src/thrift/transport/TBufferTransports.cpp
@@ -201,6 +201,11 @@ bool TFramedTransport::readFrame() {
throw TTransportException("Frame size has negative value");
}
+ // Check for oversized frame
+ if (sz > static_cast<int32_t>(maxFrameSize_))
+ throw TTransportException(TTransportException::CORRUPTED_DATA,
+ "Received an oversized frame");
+
// Read the frame payload, and reset markers.
if (sz > static_cast<int32_t>(rBufSize_)) {
rBuf_.reset(new uint8_t[sz]);
http://git-wip-us.apache.org/repos/asf/thrift/blob/0d964d8e/lib/cpp/src/thrift/transport/TBufferTransports.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TBufferTransports.h b/lib/cpp/src/thrift/transport/TBufferTransports.h
index c94ae1e..9b5d51f 100644
--- a/lib/cpp/src/thrift/transport/TBufferTransports.h
+++ b/lib/cpp/src/thrift/transport/TBufferTransports.h
@@ -305,6 +305,7 @@ public:
class TFramedTransport : public TVirtualTransport<TFramedTransport, TBufferBase> {
public:
static const int DEFAULT_BUFFER_SIZE = 512;
+ static const int DEFAULT_MAX_FRAME_SIZE = 256 * 1024 * 1024;
/// Use default buffer sizes.
TFramedTransport(boost::shared_ptr<TTransport> transport)
@@ -365,6 +366,16 @@ public:
*/
virtual const std::string getOrigin() { return transport_->getOrigin(); }
+ /**
+ * Set the maximum size of the frame at read
+ */
+ void setMaxFrameSize(uint32_t maxFrameSize) { maxFrameSize_ = maxFrameSize; }
+
+ /**
+ * Get the maximum size of the frame at read
+ */
+ uint32_t getMaxFrameSize() { return maxFrameSize_; }
+
protected:
/**
* Reads a frame of input from the underlying stream.
@@ -390,6 +401,7 @@ protected:
boost::scoped_array<uint8_t> rBuf_;
boost::scoped_array<uint8_t> wBuf_;
uint32_t bufReclaimThresh_;
+ uint32_t maxFrameSize_ = DEFAULT_MAX_FRAME_SIZE;
};
/**