#include "quiche/quic/core/quic_framer.h"
#include <algorithm>
#include <cstdint>
#include <cstring>
#include <limits>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "absl/base/macros.h"
#include "absl/memory/memory.h"
#include "absl/strings/escaping.h"
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
#include "quiche/quic/core/crypto/null_decrypter.h"
#include "quiche/quic/core/crypto/null_encrypter.h"
#include "quiche/quic/core/crypto/quic_decrypter.h"
#include "quiche/quic/core/crypto/quic_encrypter.h"
#include "quiche/quic/core/frames/quic_reset_stream_at_frame.h"
#include "quiche/quic/core/quic_connection_id.h"
#include "quiche/quic/core/quic_error_codes.h"
#include "quiche/quic/core/quic_packets.h"
#include "quiche/quic/core/quic_types.h"
#include "quiche/quic/core/quic_utils.h"
#include "quiche/quic/core/quic_versions.h"
#include "quiche/quic/platform/api/quic_expect_bug.h"
#include "quiche/quic/platform/api/quic_flags.h"
#include "quiche/quic/platform/api/quic_ip_address.h"
#include "quiche/quic/platform/api/quic_ip_address_family.h"
#include "quiche/quic/platform/api/quic_logging.h"
#include "quiche/quic/platform/api/quic_test.h"
#include "quiche/quic/test_tools/quic_framer_peer.h"
#include "quiche/quic/test_tools/quic_test_utils.h"
#include "quiche/quic/test_tools/simple_data_producer.h"
#include "quiche/common/test_tools/quiche_test_utils.h"
_;
ContainerEq;
Optional;
Return;
namespace quic {
namespace test {
namespace {
const uint64_t kEpoch = …1) << 32;
const uint64_t kMask = …;
const uint8_t kPacket0ByteConnectionId = …;
const uint8_t kPacket8ByteConnectionId = …;
constexpr size_t kTagSize = …;
const StatelessResetToken kTestStatelessResetToken{ … };
QuicConnectionId FramerTestConnectionId() { … }
QuicConnectionId FramerTestConnectionIdPlusOne() { … }
QuicConnectionId FramerTestConnectionIdNineBytes() { … }
const QuicPacketNumber kPacketNumber = …;
const QuicPacketNumber kSmallLargestObserved = …;
const QuicPacketNumber kSmallMissingPacket = …;
const QuicPacketNumber kLeastUnacked = …;
const QuicStreamId kStreamId = …0x01020304);
const QuicStreamOffset kStreamOffset = …0x3A98FEDC32107654);
const QuicPublicResetNonceProof kNonceProof = …0xABCDEF0123456789);
const QuicPacketNumber kLargestIetfLargestObserved = …;
const uint8_t kVarInt62OneByte = …;
const uint8_t kVarInt62TwoBytes = …;
const uint8_t kVarInt62FourBytes = …;
const uint8_t kVarInt62EightBytes = …;
class TestEncrypter : public QuicEncrypter { … };
class TestDecrypter : public QuicDecrypter { … };
std::unique_ptr<QuicEncryptedPacket> EncryptPacketWithTagAndPhase(
const QuicPacket& packet, uint8_t tag, bool phase) { … }
class TestQuicVisitor : public QuicFramerVisitorInterface { … };
struct PacketFragment { … };
PacketFragments;
class QuicFramerTest : public QuicTestWithParam<ParsedQuicVersion> { … };
#define QUIC_VERSION_BYTES …
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearEpochStart) { … }
TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearEpochEnd) { … }
TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearPrevEpoch) { … }
TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearNextEpoch) { … }
TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearNextMax) { … }
TEST_P(QuicFramerTest, EmptyPacket) { … }
TEST_P(QuicFramerTest, LargePacket) { … }
TEST_P(QuicFramerTest, LongPacketHeader) { … }
TEST_P(QuicFramerTest, LongPacketHeaderWithBothConnectionIds) { … }
TEST_P(QuicFramerTest, AllZeroPacketParsingFails) { … }
TEST_P(QuicFramerTest, ParsePublicHeader) { … }
TEST_P(QuicFramerTest, ParsePublicHeaderProxBadSourceConnectionIdLength) { … }
TEST_P(QuicFramerTest, ClientConnectionIdFromShortHeaderToClient) { … }
TEST_P(QuicFramerTest, ClientConnectionIdFromShortHeaderToServer) { … }
TEST_P(QuicFramerTest, PacketHeaderWith0ByteConnectionId) { … }
TEST_P(QuicFramerTest, PacketHeaderWithVersionFlag) { … }
TEST_P(QuicFramerTest, PacketHeaderWith4BytePacketNumber) { … }
TEST_P(QuicFramerTest, PacketHeaderWith2BytePacketNumber) { … }
TEST_P(QuicFramerTest, PacketHeaderWith1BytePacketNumber) { … }
TEST_P(QuicFramerTest, PacketNumberDecreasesThenIncreases) { … }
TEST_P(QuicFramerTest, PacketWithDiversificationNonce) { … }
TEST_P(QuicFramerTest, LargePublicFlagWithMismatchedVersions) { … }
TEST_P(QuicFramerTest, PaddingFrame) { … }
TEST_P(QuicFramerTest, StreamFrame) { … }
TEST_P(QuicFramerTest, EmptyStreamFrame) { … }
TEST_P(QuicFramerTest, MissingDiversificationNonce) { … }
TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) { … }
TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) { … }
TEST_P(QuicFramerTest, StreamFrameWithVersion) { … }
TEST_P(QuicFramerTest, RejectPacket) { … }
TEST_P(QuicFramerTest, RejectPublicHeader) { … }
TEST_P(QuicFramerTest, AckFrameOneAckBlock) { … }
TEST_P(QuicFramerTest, FirstAckFrameUnderflow) { … }
TEST_P(QuicFramerTest, ThirdAckBlockUnderflowGap) { … }
TEST_P(QuicFramerTest, ThirdAckBlockUnderflowAck) { … }
TEST_P(QuicFramerTest, AckBlockUnderflowGapWrap) { … }
TEST_P(QuicFramerTest, AckBlockUnderflowAckWrap) { … }
TEST_P(QuicFramerTest, AckBlockAcksEverything) { … }
TEST_P(QuicFramerTest, AckFrameFirstAckBlockLengthZero) { … }
TEST_P(QuicFramerTest, AckFrameOneAckBlockMaxLength) { … }
TEST_P(QuicFramerTest, AckFrameTwoTimeStampsMultipleAckBlocks) { … }
TEST_P(QuicFramerTest, AckFrameMultipleReceiveTimestampRanges) { … }
TEST_P(QuicFramerTest, AckFrameReceiveTimestampWithExponent) { … }
TEST_P(QuicFramerTest, AckFrameReceiveTimestampGapTooHigh) { … }
TEST_P(QuicFramerTest, AckFrameReceiveTimestampCountTooHigh) { … }
TEST_P(QuicFramerTest, AckFrameReceiveTimestampDeltaTooHigh) { … }
TEST_P(QuicFramerTest, AckFrameTimeStampDeltaTooHigh) { … }
TEST_P(QuicFramerTest, AckFrameTimeStampSecondDeltaTooHigh) { … }
TEST_P(QuicFramerTest, NewStopWaitingFrame) { … }
TEST_P(QuicFramerTest, InvalidNewStopWaitingFrame) { … }
TEST_P(QuicFramerTest, RstStreamFrame) { … }
TEST_P(QuicFramerTest, ConnectionCloseFrame) { … }
TEST_P(QuicFramerTest, ConnectionCloseFrameWithUnknownErrorCode) { … }
TEST_P(QuicFramerTest, ConnectionCloseFrameWithExtractedInfoIgnoreGCuic) { … }
TEST_P(QuicFramerTest, ApplicationCloseFrame) { … }
TEST_P(QuicFramerTest, ApplicationCloseFrameExtract) { … }
TEST_P(QuicFramerTest, GoAwayFrame) { … }
TEST_P(QuicFramerTest, GoAwayFrameWithUnknownErrorCode) { … }
TEST_P(QuicFramerTest, WindowUpdateFrame) { … }
TEST_P(QuicFramerTest, MaxDataFrame) { … }
TEST_P(QuicFramerTest, MaxStreamDataFrame) { … }
TEST_P(QuicFramerTest, BlockedFrame) { … }
TEST_P(QuicFramerTest, PingFrame) { … }
TEST_P(QuicFramerTest, HandshakeDoneFrame) { … }
TEST_P(QuicFramerTest, ParseAckFrequencyFrame) { … }
TEST_P(QuicFramerTest, ParseResetStreamAtFrame) { … }
TEST_P(QuicFramerTest, ParseInvalidResetStreamAtFrame) { … }
TEST_P(QuicFramerTest, MessageFrame) { … }
TEST_P(QuicFramerTest, IetfStatelessResetPacket) { … }
TEST_P(QuicFramerTest, IetfStatelessResetPacketInvalidStatelessResetToken) { … }
TEST_P(QuicFramerTest, VersionNegotiationPacketClient) { … }
TEST_P(QuicFramerTest, VersionNegotiationPacketServer) { … }
TEST_P(QuicFramerTest, ParseIetfRetryPacket) { … }
TEST_P(QuicFramerTest, BuildPaddingFramePacket) { … }
TEST_P(QuicFramerTest, BuildStreamFramePacketWithNewPaddingFrame) { … }
TEST_P(QuicFramerTest, Build4ByteSequenceNumberPaddingFramePacket) { … }
TEST_P(QuicFramerTest, Build2ByteSequenceNumberPaddingFramePacket) { … }
TEST_P(QuicFramerTest, Build1ByteSequenceNumberPaddingFramePacket) { … }
TEST_P(QuicFramerTest, BuildStreamFramePacket) { … }
TEST_P(QuicFramerTest, BuildStreamFramePacketWithVersionFlag) { … }
TEST_P(QuicFramerTest, BuildCryptoFramePacket) { … }
TEST_P(QuicFramerTest, CryptoFrame) { … }
TEST_P(QuicFramerTest, BuildOldVersionNegotiationPacket) { … }
TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) { … }
TEST_P(QuicFramerTest, BuildVersionNegotiationPacketWithClientConnectionId) { … }
TEST_P(QuicFramerTest, BuildAckFramePacketOneAckBlock) { … }
TEST_P(QuicFramerTest, BuildAckReceiveTimestampsFrameMultipleRanges) { … }
TEST_P(QuicFramerTest, BuildAckReceiveTimestampsFrameExceedsMaxTimestamps) { … }
TEST_P(QuicFramerTest, BuildAckReceiveTimestampsFrameWithExponentEncoding) { … }
TEST_P(QuicFramerTest, BuildAndProcessAckReceiveTimestampsWithMultipleRanges) { … }
TEST_P(QuicFramerTest,
BuildAndProcessAckReceiveTimestampsExceedsMaxTimestamps) { … }
TEST_P(QuicFramerTest,
BuildAndProcessAckReceiveTimestampsWithExponentNoTruncation) { … }
TEST_P(QuicFramerTest,
BuildAndProcessAckReceiveTimestampsWithExponentTruncation) { … }
TEST_P(QuicFramerTest, AckReceiveTimestamps) { … }
TEST_P(QuicFramerTest, AckReceiveTimestampsPacketOutOfOrder) { … }
TEST_P(QuicFramerTest, IetfAckReceiveTimestampsTruncate) { … }
TEST_P(QuicFramerTest, IetfAckReceiveTimestampsAckRangeTruncation) { … }
TEST_P(QuicFramerTest, BuildAckFramePacketOneAckBlockMaxLength) { … }
TEST_P(QuicFramerTest, BuildAckFramePacketMultipleAckBlocks) { … }
TEST_P(QuicFramerTest, BuildAckFramePacketMaxAckBlocks) { … }
TEST_P(QuicFramerTest, BuildRstFramePacketQuic) { … }
TEST_P(QuicFramerTest, BuildCloseFramePacket) { … }
TEST_P(QuicFramerTest, BuildCloseFramePacketExtendedInfo) { … }
TEST_P(QuicFramerTest, BuildTruncatedCloseFramePacket) { … }
TEST_P(QuicFramerTest, BuildApplicationCloseFramePacket) { … }
TEST_P(QuicFramerTest, BuildTruncatedApplicationCloseFramePacket) { … }
TEST_P(QuicFramerTest, BuildGoAwayPacket) { … }
TEST_P(QuicFramerTest, BuildTruncatedGoAwayPacket) { … }
TEST_P(QuicFramerTest, BuildWindowUpdatePacket) { … }
TEST_P(QuicFramerTest, BuildMaxStreamDataPacket) { … }
TEST_P(QuicFramerTest, BuildMaxDataPacket) { … }
TEST_P(QuicFramerTest, BuildBlockedPacket) { … }
TEST_P(QuicFramerTest, BuildPingPacket) { … }
TEST_P(QuicFramerTest, BuildHandshakeDonePacket) { … }
TEST_P(QuicFramerTest, BuildAckFrequencyPacket) { … }
TEST_P(QuicFramerTest, BuildResetStreamAtPacket) { … }
TEST_P(QuicFramerTest, BuildMessagePacket) { … }
TEST_P(QuicFramerTest, BuildMtuDiscoveryPacket) { … }
TEST_P(QuicFramerTest, BuildPublicResetPacket) { … }
TEST_P(QuicFramerTest, BuildPublicResetPacketWithClientAddress) { … }
TEST_P(QuicFramerTest, BuildPublicResetPacketWithEndpointId) { … }
TEST_P(QuicFramerTest, BuildIetfStatelessResetPacket) { … }
TEST_P(QuicFramerTest, BuildIetfStatelessResetPacketCallerProvidedRandomBytes) { … }
TEST_P(QuicFramerTest, EncryptPacket) { … }
TEST_P(QuicFramerTest, EncryptEmptyPacket) { … }
TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) { … }
TEST_P(QuicFramerTest, AckTruncationLargePacket) { … }
TEST_P(QuicFramerTest, IetfAckFrameTruncation) { … }
TEST_P(QuicFramerTest, AckTruncationSmallPacket) { … }
TEST_P(QuicFramerTest, CleanTruncation) { … }
TEST_P(QuicFramerTest, StopPacketProcessing) { … }
static char kTestString[] = …;
static QuicStreamId kTestQuicStreamId = …;
MATCHER_P(ExpectedStreamFrame, version, "") { … }
TEST_P(QuicFramerTest, ConstructEncryptedPacket) { … }
TEST_P(QuicFramerTest, ConstructMisFramedEncryptedPacket) { … }
TEST_P(QuicFramerTest, IetfBlockedFrame) { … }
TEST_P(QuicFramerTest, BuildIetfBlockedPacket) { … }
TEST_P(QuicFramerTest, IetfStreamBlockedFrame) { … }
TEST_P(QuicFramerTest, BuildIetfStreamBlockedPacket) { … }
TEST_P(QuicFramerTest, BiDiMaxStreamsFrame) { … }
TEST_P(QuicFramerTest, UniDiMaxStreamsFrame) { … }
TEST_P(QuicFramerTest, ServerUniDiMaxStreamsFrame) { … }
TEST_P(QuicFramerTest, ClientUniDiMaxStreamsFrame) { … }
TEST_P(QuicFramerTest, BiDiMaxStreamsFrameTooBig) { … }
TEST_P(QuicFramerTest, ClientBiDiMaxStreamsFrameTooBig) { … }
TEST_P(QuicFramerTest, ServerUniDiMaxStreamsFrameTooBig) { … }
TEST_P(QuicFramerTest, ClientUniDiMaxStreamsFrameTooBig) { … }
TEST_P(QuicFramerTest, MaxStreamsFrameZeroCount) { … }
TEST_P(QuicFramerTest, ServerBiDiStreamsBlockedFrame) { … }
TEST_P(QuicFramerTest, BiDiStreamsBlockedFrame) { … }
TEST_P(QuicFramerTest, UniDiStreamsBlockedFrame) { … }
TEST_P(QuicFramerTest, ClientUniDiStreamsBlockedFrame) { … }
TEST_P(QuicFramerTest, StreamsBlockedFrameTooBig) { … }
TEST_P(QuicFramerTest, StreamsBlockedFrameZeroCount) { … }
TEST_P(QuicFramerTest, BuildBiDiStreamsBlockedPacket) { … }
TEST_P(QuicFramerTest, BuildUniStreamsBlockedPacket) { … }
TEST_P(QuicFramerTest, BuildBiDiMaxStreamsPacket) { … }
TEST_P(QuicFramerTest, BuildUniDiMaxStreamsPacket) { … }
TEST_P(QuicFramerTest, NewConnectionIdFrame) { … }
TEST_P(QuicFramerTest, NewConnectionIdFrameVariableLength) { … }
TEST_P(QuicFramerTest, InvalidLongNewConnectionIdFrame) { … }
TEST_P(QuicFramerTest, InvalidRetirePriorToNewConnectionIdFrame) { … }
TEST_P(QuicFramerTest, BuildNewConnectionIdFramePacket) { … }
TEST_P(QuicFramerTest, NewTokenFrame) { … }
TEST_P(QuicFramerTest, BuildNewTokenFramePacket) { … }
TEST_P(QuicFramerTest, IetfStopSendingFrame) { … }
TEST_P(QuicFramerTest, BuildIetfStopSendingPacket) { … }
TEST_P(QuicFramerTest, IetfPathChallengeFrame) { … }
TEST_P(QuicFramerTest, BuildIetfPathChallengePacket) { … }
TEST_P(QuicFramerTest, IetfPathResponseFrame) { … }
TEST_P(QuicFramerTest, BuildIetfPathResponsePacket) { … }
TEST_P(QuicFramerTest, GetRetransmittableControlFrameSize) { … }
TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown1Byte) { … }
TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown2Bytes) { … }
TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown4Bytes) { … }
TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown8Bytes) { … }
TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown2Bytes) { … }
TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown4Bytes) { … }
TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown8Bytes) { … }
TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown2BytesAllTypes) { … }
TEST_P(QuicFramerTest, RetireConnectionIdFrame) { … }
TEST_P(QuicFramerTest, BuildRetireConnectionIdFramePacket) { … }
TEST_P(QuicFramerTest, AckFrameWithInvalidLargestObserved) { … }
TEST_P(QuicFramerTest, FirstAckBlockJustUnderFlow) { … }
TEST_P(QuicFramerTest, ThirdAckBlockJustUnderflow) { … }
TEST_P(QuicFramerTest, CoalescedPacket) { … }
TEST_P(QuicFramerTest, CoalescedPacketWithUdpPadding) { … }
TEST_P(QuicFramerTest, CoalescedPacketWithDifferentVersion) { … }
TEST_P(QuicFramerTest, UndecryptablePacketWithoutDecrypter) { … }
TEST_P(QuicFramerTest, UndecryptablePacketWithDecrypter) { … }
TEST_P(QuicFramerTest, UndecryptableCoalescedPacket) { … }
TEST_P(QuicFramerTest, MismatchedCoalescedPacket) { … }
TEST_P(QuicFramerTest, InvalidCoalescedPacket) { … }
TEST_P(QuicFramerTest, CoalescedPacketWithZeroesRoundTrip) { … }
TEST_P(QuicFramerTest, ClientReceivesWrongVersion) { … }
TEST_P(QuicFramerTest, PacketHeaderWithVariableLengthConnectionId) { … }
TEST_P(QuicFramerTest, MultiplePacketNumberSpaces) { … }
TEST_P(QuicFramerTest, IetfRetryPacketRejected) { … }
TEST_P(QuicFramerTest, RetryPacketRejectedWithMultiplePacketNumberSpaces) { … }
TEST_P(QuicFramerTest, WriteClientVersionNegotiationProbePacket) { … }
TEST_P(QuicFramerTest, DispatcherParseOldClientVersionNegotiationProbePacket) { … }
TEST_P(QuicFramerTest, DispatcherParseClientVersionNegotiationProbePacket) { … }
TEST_P(QuicFramerTest, DispatcherParseClientInitialPacketNumber) { … }
TEST_P(QuicFramerTest,
DispatcherParseClientInitialPacketNumberFromCoalescedPacket) { … }
TEST_P(QuicFramerTest, ParseServerVersionNegotiationProbeResponse) { … }
TEST_P(QuicFramerTest, ParseClientVersionNegotiationProbePacket) { … }
TEST_P(QuicFramerTest, WriteServerVersionNegotiationProbeResponse) { … }
TEST_P(QuicFramerTest, ClientConnectionIdFromLongHeaderToClient) { … }
TEST_P(QuicFramerTest, ClientConnectionIdFromLongHeaderToServer) { … }
TEST_P(QuicFramerTest, ProcessAndValidateIetfConnectionIdLengthClient) { … }
TEST_P(QuicFramerTest, ProcessAndValidateIetfConnectionIdLengthServer) { … }
TEST_P(QuicFramerTest, TestExtendedErrorCodeParser) { … }
TEST_P(QuicFramerTest, OverlyLargeAckDelay) { … }
TEST_P(QuicFramerTest, KeyUpdate) { … }
TEST_P(QuicFramerTest, KeyUpdateOldPacketAfterUpdate) { … }
TEST_P(QuicFramerTest, KeyUpdateOldPacketAfterDiscardPreviousOneRttKeys) { … }
TEST_P(QuicFramerTest, KeyUpdatePacketsOutOfOrder) { … }
TEST_P(QuicFramerTest, KeyUpdateWrongKey) { … }
TEST_P(QuicFramerTest, KeyUpdateReceivedWhenNotEnabled) { … }
TEST_P(QuicFramerTest, KeyUpdateLocallyInitiated) { … }
TEST_P(QuicFramerTest, KeyUpdateLocallyInitiatedReceivedOldPacket) { … }
TEST_P(QuicFramerTest, KeyUpdateOnFirstReceivedPacket) { … }
TEST_P(QuicFramerTest, ErrorWhenUnexpectedFrameTypeEncountered) { … }
TEST_P(QuicFramerTest, ShortHeaderWithNonDefaultConnectionIdLength) { … }
TEST_P(QuicFramerTest, ReportEcnCountsIfPresent) { … }
}
}
}