diff --git a/quic/codec/PacketNumber.cpp b/quic/codec/PacketNumber.cpp index 8685196da..bfc0996f2 100644 --- a/quic/codec/PacketNumber.cpp +++ b/quic/codec/PacketNumber.cpp @@ -11,7 +11,6 @@ #include #include #include -#include namespace quic { @@ -29,15 +28,8 @@ PacketNumEncodingResult encodePacketNumber( size_t lengthInBits = folly::findLastSet(twiceDistance); // Round up to bytes size_t lengthInBytes = lengthInBits == 0 ? 1 : (lengthInBits + 7) >> 3; - if (lengthInBytes > 4) { - throw QuicInternalException( - folly::to( - "Impossible to encode PacketNum=", - packetNum, - ", largestAcked=", - largestAckedPacketNum), - LocalErrorCode::PACKET_NUMBER_ENCODING); - } + CHECK(lengthInBytes <= 4) << "Impossible to encode PacketNum=" << packetNum + << ", largestAcked=" << largestAckedPacketNum; // We need a mask that's all 1 for lengthInBytes bytes. Left shift a 1 by that // many bits and then -1 will give us that. Or if lengthInBytes is 8, then ~0 // will just do it. diff --git a/quic/codec/QuicInteger.h b/quic/codec/QuicInteger.h index 78ef8a418..eae16d7d9 100644 --- a/quic/codec/QuicInteger.h +++ b/quic/codec/QuicInteger.h @@ -136,22 +136,14 @@ class QuicInteger { template size_t encode(BufOp appender) const { auto size = encodeQuicInteger(value_, std::move(appender)); - if (size.hasError()) { - LOG(ERROR) << "Value too large value=" << value_; - throw QuicTransportException( - folly::to("Value too large ", value_), size.error()); - } + CHECK(!size.hasError()) << "Value too large value=" << value_; return size.value(); } template size_t encode(BufOp appender, int outputSize) const { auto size = encodeQuicInteger(value_, std::move(appender), outputSize); - if (size.hasError()) { - LOG(ERROR) << "Value too large value=" << value_; - throw QuicTransportException( - folly::to("Value too large ", value_), size.error()); - } + CHECK(!size.hasError()) << "Value too large value=" << value_; return size.value(); } diff --git a/quic/codec/QuicWriteCodec.cpp b/quic/codec/QuicWriteCodec.cpp index c52fa7dee..c9fa8ba95 100644 --- a/quic/codec/QuicWriteCodec.cpp +++ b/quic/codec/QuicWriteCodec.cpp @@ -106,8 +106,7 @@ folly::Expected, QuicError> writeStreamFrameHeader( } else { // This should never really happen as dataLen is bounded by the remaining // space in the packet which should be << kEightByteLimit. - throw QuicInternalException( - "Stream frame length too large.", LocalErrorCode::INTERNAL_ERROR); + LOG(FATAL) << "Stream frame length too large."; } } if (dataLenLen > 0) { @@ -198,11 +197,8 @@ Optional writeCryptoFrame( size_t writableData = std::min(dataLength, spaceRemaining); QuicInteger lengthVarInt(writableData); - if (lengthVarInt.getSize() > lengthBytes) { - throw QuicInternalException( - std::string("Length bytes representation"), - LocalErrorCode::CODEC_ERROR); - } + CHECK(lengthVarInt.getSize() <= lengthBytes) + << "Length bytes representation exceeds allocated space"; builder.write(intFrameType); builder.write(offsetInteger); builder.write(lengthVarInt); @@ -1070,11 +1066,7 @@ size_t writeFrame(QuicWriteFrame&& frame, PacketBuilderInterface& builder) { return size_t(0); } default: { - auto errorStr = folly::to( - "Unknown / unsupported frame type received at ", __func__); - VLOG(2) << errorStr; - throw QuicTransportException( - errorStr, TransportErrorCode::FRAME_ENCODING_ERROR); + LOG(FATAL) << "Unknown / unsupported frame type received"; } } } diff --git a/quic/codec/Types.cpp b/quic/codec/Types.cpp index 2feb2d387..c7cd60758 100644 --- a/quic/codec/Types.cpp +++ b/quic/codec/Types.cpp @@ -255,21 +255,19 @@ ShortHeader::ShortHeader( ConnectionId connId, PacketNum packetNum) : protectionType_(protectionType), connectionId_(std::move(connId)) { - if (protectionType_ != ProtectionType::KeyPhaseZero && - protectionType_ != ProtectionType::KeyPhaseOne) { - throw QuicInternalException( - "bad short header protection type", LocalErrorCode::CODEC_ERROR); - } + CHECK( + protectionType_ == ProtectionType::KeyPhaseZero || + protectionType_ == ProtectionType::KeyPhaseOne) + << "bad short header protection type"; setPacketNumber(packetNum); } ShortHeader::ShortHeader(ProtectionType protectionType, ConnectionId connId) : protectionType_(protectionType), connectionId_(std::move(connId)) { - if (protectionType_ != ProtectionType::KeyPhaseZero && - protectionType_ != ProtectionType::KeyPhaseOne) { - throw QuicInternalException( - "bad short header protection type", LocalErrorCode::CODEC_ERROR); - } + CHECK( + protectionType_ == ProtectionType::KeyPhaseZero || + protectionType_ == ProtectionType::KeyPhaseOne) + << "bad short header protection type"; } ProtectionType ShortHeader::getProtectionType() const {