src/net/third_party/quiche/src/quic/test_tools/fuzzing/quic_framer_process_data_packet_fuzzer.cc
// Construct a random data packet header that 1) can be successfully serialized
// at sender, and 2) the serialzied buffer can pass the receiver framer's
// ProcessPublicHeader and DecryptPayload functions.
Construct a random data packet header that 1) can be successfully serialized
at sender, and 2) the serialzied buffer can pass the receiver framer's
ProcessPublicHeader and DecryptPayload functions.
Construct a random data packet header that 1 ) can be successfully serialized at sender and 2 ) the serialzied buffer can pass the receiver framer ' s ProcessPublicHeader and DecryptPayload functions .
QuicSelfContainedPacketHeader ConsumeQuicPacketHeader(
    FuzzedDataProvider* provider,
    Perspective receiver_perspective) {
  QuicSelfContainedPacketHeader header;
  header.version = ConsumeParsedQuicVersion(provider);
  header.form = ConsumePacketHeaderFormat(provider, header.version);
  const std::string cid_bytes =
      provider->ConsumeBytesAsString(kQuicDefaultConnectionIdLength);
  if (receiver_perspective == Perspective::IS_SERVER) {
    header.destination_connection_id =
        QuicConnectionId(cid_bytes.c_str(), cid_bytes.size());
    header.destination_connection_id_included = quic::CONNECTION_ID_PRESENT;
    header.source_connection_id_included = quic::CONNECTION_ID_ABSENT;
  } else {
    header.source_connection_id =
        QuicConnectionId(cid_bytes.c_str(), cid_bytes.size());
    header.source_connection_id_included = quic::CONNECTION_ID_PRESENT;
    header.destination_connection_id_included = quic::CONNECTION_ID_ABSENT;
  }
  header.version_flag = receiver_perspective == Perspective::IS_SERVER;
  header.reset_flag = false;
  header.packet_number =
      QuicPacketNumber(provider->ConsumeIntegral<uint32_t>());
  if (header.packet_number < FirstSendingPacketNumber()) {
    header.packet_number = FirstSendingPacketNumber();
  }
  header.packet_number_length = quic::PACKET_4BYTE_PACKET_NUMBER;
  header.remaining_packet_length = 0;
  if (header.form != quic::GOOGLE_QUIC_PACKET && header.version_flag) {
    header.long_packet_type = static_cast<QuicLongHeaderType>(
        provider->ConsumeIntegralInRange<uint8_t>(
            static_cast<uint8_t>(quic::INITIAL),
            static_cast<uint8_t>(quic::HANDSHAKE)));
  } else {
    header.long_packet_type = quic::INVALID_PACKET_TYPE;
  }
  if (header.form == quic::IETF_QUIC_LONG_HEADER_PACKET &&
      header.long_packet_type == quic::ZERO_RTT_PROTECTED &&
      receiver_perspective == Perspective::IS_CLIENT &&
      header.version.handshake_protocol == quic::PROTOCOL_QUIC_CRYPTO) {
    for (size_t i = 0; i < header.nonce_storage.size(); ++i) {
      header.nonce_storage[i] = provider->ConsumeIntegral<char>();
    }
    header.nonce = &header.nonce_storage;
  } else {
    header.nonce = nullptr;
  }
  return header;
}
QuicSelfContainedPacketHeader ConsumeQuicPacketHeader ( FuzzedDataProvider * provider , Perspective receiver_perspective ) { QuicSelfContainedPacketHeader header ; header . version = ConsumeParsedQuicVersion ( provider ) ; header . form = ConsumePacketHeaderFormat ( provider , header . version ) ; const std :: string cid_bytes = provider -> ConsumeBytesAsString ( kQuicDefaultConnectionIdLength ) ; if ( receiver_perspective == Perspective :: IS_SERVER ) { header . destination_connection_id = QuicConnectionId ( cid_bytes . c_str ( ) , cid_bytes . size ( ) ) ; header . destination_connection_id_included = quic :: CONNECTION_ID_PRESENT ; header . source_connection_id_included = quic :: CONNECTION_ID_ABSENT ; } else { header . source_connection_id = QuicConnectionId ( cid_bytes . c_str ( ) , cid_bytes . size ( ) ) ; header . source_connection_id_included = quic :: CONNECTION_ID_PRESENT ; header . destination_connection_id_included = quic :: CONNECTION_ID_ABSENT ; } header . version_flag = receiver_perspective == Perspective :: IS_SERVER ; header . reset_flag = false ; header . packet_number = QuicPacketNumber ( provider -> ConsumeIntegral < uint32_t > ( ) ) ; if ( header . packet_number < FirstSendingPacketNumber ( ) ) { header . packet_number = FirstSendingPacketNumber ( ) ; } header . packet_number_length = quic :: PACKET_4BYTE_PACKET_NUMBER ; header . remaining_packet_length = 0 ; if ( header . form != quic :: GOOGLE_QUIC_PACKET && header . version_flag ) { header . long_packet_type = static_cast < QuicLongHeaderType > ( provider -> ConsumeIntegralInRange < uint8_t > ( static_cast < uint8_t > ( quic :: INITIAL ) , static_cast < uint8_t > ( quic :: HANDSHAKE ) ) ) ; } else { header . long_packet_type = quic :: INVALID_PACKET_TYPE ; } if ( header . form == quic :: IETF_QUIC_LONG_HEADER_PACKET && header . long_packet_type == quic :: ZERO_RTT_PROTECTED && receiver_perspective == Perspective :: IS_CLIENT && header . version . handshake_protocol == quic :: PROTOCOL_QUIC_CRYPTO ) { for ( size_t i = 0 ; i < header . nonce_storage . size ( ) ; ++ i ) { header . nonce_storage [ i ] = provider -> ConsumeIntegral < char > ( ) ; } header . nonce = & header . nonce_storage ; } else { header . nonce = nullptr ; } return header ; }
Construct a random data packet header that 1) can be successfully serialized
at sender, and 2) the serialzied buffer can pass the receiver framer's
ProcessPublicHeader and DecryptPayload functions.
Construct a random data packet header that 1 ) can be successfully serialized at sender and 2 ) the serialzied buffer can pass the receiver framer ' s ProcessPublicHeader and DecryptPayload functions .
// INITIAL, ZERO_RTT_PROTECTED, or HANDSHAKE.