You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by ya...@apache.org on 2022/08/03 05:19:50 UTC
[doris-thirdparty] 16/21: fix warning
This is an automated email from the ASF dual-hosted git repository.
yangzhg pushed a commit to branch libhdfs3
in repository https://gitbox.apache.org/repos/asf/doris-thirdparty.git
commit 2c79aa514681df02c39b5b2a043fc1bea9532e9a
Author: yangzhg <ya...@gmail.com>
AuthorDate: Wed Jun 8 11:13:42 2022 +0800
fix warning
---
src/client/DataTransferProtocolSender.cpp | 8 +++++
src/client/FileEncryptionInfo.h | 2 +-
src/client/FileSystemImpl.cpp | 3 +-
src/client/PacketHeader.cpp | 22 ++++++++++++--
src/client/RemoteBlockReader.cpp | 10 ++++++-
src/rpc/RpcContentWrapper.cpp | 49 ++++++++++++++++++++++++++-----
src/rpc/RpcRemoteCall.cpp | 28 ++++++++++++++----
src/server/NamenodeImpl.cpp | 1 +
8 files changed, 105 insertions(+), 18 deletions(-)
diff --git a/src/client/DataTransferProtocolSender.cpp b/src/client/DataTransferProtocolSender.cpp
index ff62e9b..564b006 100644
--- a/src/client/DataTransferProtocolSender.cpp
+++ b/src/client/DataTransferProtocolSender.cpp
@@ -38,7 +38,15 @@ static inline void Send(Socket & sock, DataTransferOp op, Message * msg,
WriteBuffer buffer;
buffer.writeBigEndian(static_cast<int16_t>(DATA_TRANSFER_VERSION));
buffer.write(static_cast<char>(op));
+ #if GOOGLE_PROTOBUF_VERSION >= 3010000
+ size_t size_raw = msg->ByteSizeLong();
+ if (size_raw > INT_MAX) {
+ THROW(HdfsIOException, "Hdfs::Internal::Send: msg message is too large: %zu", size_raw);
+ }
+ int msgSize = static_cast<int>(size_raw);
+ #else
int msgSize = msg->ByteSize();
+ #endif
buffer.writeVarint32(msgSize);
char * b = buffer.alloc(msgSize);
diff --git a/src/client/FileEncryptionInfo.h b/src/client/FileEncryptionInfo.h
index 32ead6c..671665d 100644
--- a/src/client/FileEncryptionInfo.h
+++ b/src/client/FileEncryptionInfo.h
@@ -29,7 +29,7 @@ namespace Hdfs {
class FileEncryptionInfo {
public:
FileEncryptionInfo() :
- cryptoProtocolVersion(0), suite(0){
+ suite(0), cryptoProtocolVersion(0){
}
int getSuite() const {
diff --git a/src/client/FileSystemImpl.cpp b/src/client/FileSystemImpl.cpp
index 6ee2b91..a9676c9 100644
--- a/src/client/FileSystemImpl.cpp
+++ b/src/client/FileSystemImpl.cpp
@@ -852,8 +852,7 @@ std::vector<EncryptionZoneInfo> FileSystemImpl::listAllEncryptionZoneItems() {
std::vector<EncryptionZoneInfo> retval;
retval.clear();
- int64_t id = 0;
-
+
EncryptionZoneIterator it;
it = FileSystemImpl::listEncryptionZone();
diff --git a/src/client/PacketHeader.cpp b/src/client/PacketHeader.cpp
index 6016738..0090917 100644
--- a/src/client/PacketHeader.cpp
+++ b/src/client/PacketHeader.cpp
@@ -35,7 +35,16 @@ int PacketHeader::CalcPkgHeaderSize() {
header.set_datalen(0);
header.set_lastpacketinblock(false);
header.set_seqno(0);
- return header.ByteSize() + sizeof(int32_t) /*packet length*/ + sizeof(int16_t)/* proto length */;
+ #if GOOGLE_PROTOBUF_VERSION >= 3010000
+ size_t size_raw = header.ByteSizeLong();
+ if (size_raw > INT_MAX) {
+ THROW(HdfsIOException, "PacketHeader::CalcPkgHeaderSize: header message is too large: %zu", size_raw);
+ }
+ int headerLen = static_cast<int>(size_raw);
+ #else
+ int headerLen = header.ByteSize());
+ #endif
+ return headerLen + sizeof(int32_t) /*packet length*/ + sizeof(int16_t)/* proto length */;
}
int PacketHeader::GetPkgHeaderSize() {
@@ -112,7 +121,16 @@ void PacketHeader::readFields(const char * buf, size_t size) {
void PacketHeader::writeInBuffer(char * buf, size_t size) {
buf = WriteBigEndian32ToArray(packetLen, buf);
- buf = WriteBigEndian16ToArray(proto.ByteSize(), buf);
+ #if GOOGLE_PROTOBUF_VERSION >= 3010000
+ size_t size_raw = proto.ByteSizeLong();
+ if (size_raw > INT_MAX) {
+ THROW(HdfsIOException, "PacketHeader::writeInBuffer: proto message is too large: %zu", size_raw);
+ }
+ int protoLen = static_cast<int>(size_raw);
+ #else
+ int protoLen = proto.ByteSize();
+ #endif
+ buf = WriteBigEndian16ToArray(protoLen, buf);
proto.SerializeToArray(buf, size - sizeof(int32_t) - sizeof(int16_t));
}
diff --git a/src/client/RemoteBlockReader.cpp b/src/client/RemoteBlockReader.cpp
index 54e21b7..d7faf6e 100644
--- a/src/client/RemoteBlockReader.cpp
+++ b/src/client/RemoteBlockReader.cpp
@@ -273,7 +273,15 @@ void RemoteBlockReader::sendStatus() {
}
WriteBuffer buffer;
- int size = status.ByteSize();
+ #if GOOGLE_PROTOBUF_VERSION >= 3010000
+ size_t size_raw = status.ByteSizeLong();
+ if (size_raw > INT_MAX) {
+ THROW(HdfsIOException, "RemoteBlockReader: status message is too large: %zu", size_raw);
+ }
+ int size = static_cast<int>(size_raw);
+ #else
+ int size = status.ByteSize());
+ #endif
buffer.writeVarint32(size);
status.SerializeToArray(buffer.alloc(size), size);
sock->writeFully(buffer.getBuffer(0), buffer.getDataSize(0), writeTimeout);
diff --git a/src/rpc/RpcContentWrapper.cpp b/src/rpc/RpcContentWrapper.cpp
index 2e29d17..d55dd3f 100644
--- a/src/rpc/RpcContentWrapper.cpp
+++ b/src/rpc/RpcContentWrapper.cpp
@@ -21,6 +21,8 @@
*/
#include <google/protobuf/io/coded_stream.h>
+#include "Exception.h"
+#include "ExceptionInternal.h"
#include "RpcContentWrapper.h"
using namespace ::google::protobuf;
@@ -35,22 +37,55 @@ RpcContentWrapper::RpcContentWrapper(Message * header, Message * msg) :
int RpcContentWrapper::getLength() {
int headerLen, msgLen = 0;
- headerLen = header->ByteSize();
+ #if GOOGLE_PROTOBUF_VERSION >= 3010000
+ size_t size_raw = header->ByteSizeLong();
+ if (size_raw > INT_MAX) {
+ THROW(HdfsIOException, "RpcContentWrapper::getLength: "
+ "header size is too large: %zu", size_raw);
+ }
+ headerLen = static_cast<int>(size_raw);
+ size_raw = msg == NULL ? 0 : msg->ByteSizeLong();;
+ if (size_raw > INT_MAX) {
+ THROW(HdfsIOException, "RpcContentWrapper::getLength: "
+ "msg size is too large: %zu", size_raw);
+ }
+ msgLen = static_cast<int>(size_raw);
+ #else
+ headerLen = header->ByteSize());
msgLen = msg == NULL ? 0 : msg->ByteSize();
+ #endif
return headerLen + CodedOutputStream::VarintSize32(headerLen)
+ (msg == NULL ?
0 : msgLen + CodedOutputStream::VarintSize32(msgLen));
}
void RpcContentWrapper::writeTo(WriteBuffer & buffer) {
- int size = header->ByteSize();
- buffer.writeVarint32(size);
- header->SerializeToArray(buffer.alloc(size), size);
+ #if GOOGLE_PROTOBUF_VERSION >= 3010000
+ size_t size_raw = header->ByteSizeLong();
+ if (size_raw > INT_MAX) {
+ THROW(HdfsIOException, "RpcContentWrapper::writeTo: "
+ "header size is too large: %zu", size_raw);
+ }
+ int headerLen = static_cast<int>(size_raw);
+ #else
+ int headerLen = header->ByteSize());
+ #endif
+ buffer.writeVarint32(headerLen);
+ header->SerializeToArray(buffer.alloc(headerLen), headerLen);
if (msg != NULL) {
- size = msg->ByteSize();
- buffer.writeVarint32(size);
- msg->SerializeToArray(buffer.alloc(size), size);
+ #if GOOGLE_PROTOBUF_VERSION >= 3010000
+ size_t size_raw = msg->ByteSizeLong();
+ if (size_raw > INT_MAX) {
+ THROW(HdfsIOException, "RpcContentWrapper::writeTo: "
+ "msg size is too large: %zu", size_raw);
+ }
+ int msgLen = static_cast<int>(size_raw);
+ #else
+ int msgLen = msg->ByteSize());
+ #endif
+ buffer.writeVarint32(msgLen);
+ msg->SerializeToArray(buffer.alloc(msgLen), msgLen);
}
}
diff --git a/src/rpc/RpcRemoteCall.cpp b/src/rpc/RpcRemoteCall.cpp
index fc4d2c2..cf3e668 100644
--- a/src/rpc/RpcRemoteCall.cpp
+++ b/src/rpc/RpcRemoteCall.cpp
@@ -19,6 +19,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+#include "Exception.h"
#include "Memory.h"
#include "ProtobufRpcEngine.pb.h"
#include "RpcCall.h"
@@ -49,7 +51,15 @@ void RpcRemoteCall::serialize(const RpcProtocolInfo & protocol,
requestHeader.set_declaringclassprotocolname(protocol.getProtocol());
requestHeader.set_clientprotocolversion(protocol.getVersion());
RpcContentWrapper wrapper(&requestHeader, call.getRequest());
- int rpcHeaderLen = rpcHeader.ByteSize();
+ #if GOOGLE_PROTOBUF_VERSION >= 3010000
+ size_t size_raw = rpcHeader.ByteSizeLong();
+ if (size_raw > INT_MAX) {
+ THROW(HdfsIOException, "RpcRemoteCall::serialize: rpcHeader message is too large: %zu", size_raw);
+ }
+ int rpcHeaderLen = static_cast<int>(size_raw);
+ #else
+ int rpcHeaderLen = rpcHeader.ByteSize());
+ #endif
int size = CodedOutputStream::VarintSize32(rpcHeaderLen) + rpcHeaderLen + wrapper.getLength();
buffer.writeBigEndian(size);
buffer.writeVarint32(rpcHeaderLen);
@@ -66,11 +76,19 @@ std::vector<char> RpcRemoteCall::GetPingRequest(const std::string & clientid) {
pingHeader.set_retrycount(INVALID_RETRY_COUNT);
pingHeader.set_rpckind(RpcKindProto::RPC_PROTOCOL_BUFFER);
pingHeader.set_rpcop(RpcRequestHeaderProto_OperationProto_RPC_FINAL_PACKET);
- int rpcHeaderLen = pingHeader.ByteSize();
- int size = CodedOutputStream::VarintSize32(rpcHeaderLen) + rpcHeaderLen;
+ #if GOOGLE_PROTOBUF_VERSION >= 3010000
+ size_t size_raw = pingHeader.ByteSizeLong();
+ if (size_raw > INT_MAX) {
+ THROW(HdfsIOException, "RpcRemoteCall::GetPingRequest: pingHeader message is too large: %zu", size_raw);
+ }
+ int pingHeaderLen = static_cast<int>(size_raw);
+ #else
+ int pingHeaderLen = pingHeader.ByteSize());
+ #endif
+ int size = CodedOutputStream::VarintSize32(pingHeaderLen) + pingHeaderLen;
buffer.writeBigEndian(size);
- buffer.writeVarint32(rpcHeaderLen);
- pingHeader.SerializeWithCachedSizesToArray(reinterpret_cast<unsigned char *>(buffer.alloc(pingHeader.ByteSize())));
+ buffer.writeVarint32(pingHeaderLen);
+ pingHeader.SerializeWithCachedSizesToArray(reinterpret_cast<unsigned char *>(buffer.alloc(pingHeaderLen)));
retval.resize(buffer.getDataSize(0));
memcpy(&retval[0], buffer.getBuffer(0), retval.size());
return retval;
diff --git a/src/server/NamenodeImpl.cpp b/src/server/NamenodeImpl.cpp
index 958f6b1..ac7a6ce 100644
--- a/src/server/NamenodeImpl.cpp
+++ b/src/server/NamenodeImpl.cpp
@@ -863,6 +863,7 @@ bool NamenodeImpl::listEncryptionZones(const int64_t id, std::vector<EncryptionZ
UnresolvedLinkException, HdfsIOException > unwrapper(e);
unwrapper.unwrap(__FILE__, __LINE__);
}
+ THROW(HdfsException, "unreachable code!");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org