in wangle/codec/LengthFieldBasedFrameDecoder.cpp [42:86]
bool LengthFieldBasedFrameDecoder::decode(
Context* ctx,
IOBufQueue& buf,
std::unique_ptr<IOBuf>& result,
size_t&) {
// discarding too long frame
if (buf.chainLength() < lengthFieldEndOffset_) {
return false;
}
uint64_t frameLength = getUnadjustedFrameLength(
buf, lengthFieldOffset_, lengthFieldLength_, networkByteOrder_);
frameLength += lengthAdjustment_ + lengthFieldEndOffset_;
if (frameLength < lengthFieldEndOffset_) {
buf.trimStart(lengthFieldEndOffset_);
ctx->fireReadException(
folly::make_exception_wrapper<std::runtime_error>("Frame too small"));
return false;
}
if (frameLength > maxFrameLength_) {
buf.trimStartAtMost(frameLength);
ctx->fireReadException(folly::make_exception_wrapper<std::runtime_error>(
"Frame larger than " + folly::to<std::string>(maxFrameLength_)));
return false;
}
if (buf.chainLength() < frameLength) {
return false;
}
if (initialBytesToStrip_ > frameLength) {
buf.trimStart(frameLength);
ctx->fireReadException(folly::make_exception_wrapper<std::runtime_error>(
"InitialBytesToSkip larger than frame"));
return false;
}
buf.trimStart(initialBytesToStrip_);
int actualFrameLength = static_cast<int>(frameLength) - initialBytesToStrip_;
result = buf.split(actualFrameLength);
return true;
}