Commit 8ca037ff authored by Ryan Hamilton's avatar Ryan Hamilton Committed by Commit Bot

Truncate long error details in QUIC frames to 256 bytes.

Protected by enabled flag FLAGS_quic_reloadable_flag_quic_truncate_long_details.

merge internal change: 175959960

BUG=785223

Cq-Include-Trybots: master.tryserver.chromium.android:android_cronet_tester;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Id7e15f179c7db5a19e86ddb9b474d96d2bd14342
Reviewed-on: https://chromium-review.googlesource.com/773405
Commit-Queue: Ryan Hamilton <rch@chromium.org>
Reviewed-by: default avatarZhongyi Shi <zhongyi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517477}
parent 2fff6665
......@@ -200,3 +200,7 @@ QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_bbr_less_probe_rtt, false)
QUIC_FLAG(bool,
FLAGS_quic_reloadable_flag_quic_server_reply_to_connectivity_probing,
true)
// If true, truncates QUIC error strings to 256 characters before writing them
// to the wire.
QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_truncate_long_details, true)
......@@ -103,6 +103,9 @@ const uint8_t kLargestAckedOffset = 2;
const uint8_t kQuicHasMultipleAckBlocksOffset_Pre40 = 5;
const uint8_t kQuicHasMultipleAckBlocksOffset = 4;
// Maximum length of encoded error strings.
const int kMaxErrorStringLength = 256;
// Returns the absolute value of the difference between |a| and |b|.
QuicPacketNumber Delta(QuicPacketNumber a, QuicPacketNumber b) {
// Since these are unsigned numbers, we can't just return abs(a - b)
......@@ -1885,9 +1888,11 @@ size_t QuicFramer::ComputeFrameLength(
return GetRstStreamFrameSize();
case CONNECTION_CLOSE_FRAME:
return GetMinConnectionCloseFrameSize() +
frame.connection_close_frame->error_details.size();
TruncateErrorString(frame.connection_close_frame->error_details)
.size();
case GOAWAY_FRAME:
return GetMinGoAwayFrameSize() + frame.goaway_frame->reason_phrase.size();
return GetMinGoAwayFrameSize() +
TruncateErrorString(frame.goaway_frame->reason_phrase).size();
case WINDOW_UPDATE_FRAME:
return GetWindowUpdateFrameSize();
case BLOCKED_FRAME:
......@@ -2373,7 +2378,7 @@ bool QuicFramer::AppendConnectionCloseFrame(
if (!writer->WriteUInt32(error_code)) {
return false;
}
if (!writer->WriteStringPiece16(frame.error_details)) {
if (!writer->WriteStringPiece16(TruncateErrorString(frame.error_details))) {
return false;
}
return true;
......@@ -2389,7 +2394,7 @@ bool QuicFramer::AppendGoAwayFrame(const QuicGoAwayFrame& frame,
if (!writer->WriteUInt32(stream_id)) {
return false;
}
if (!writer->WriteStringPiece16(frame.reason_phrase)) {
if (!writer->WriteStringPiece16(TruncateErrorString(frame.reason_phrase))) {
return false;
}
return true;
......@@ -2466,4 +2471,13 @@ bool QuicFramer::StartsWithChlo(QuicStreamId id,
0;
}
QuicStringPiece QuicFramer::TruncateErrorString(QuicStringPiece error) {
if (error.length() <= kMaxErrorStringLength ||
!FLAGS_quic_reloadable_flag_quic_truncate_long_details) {
return error;
}
QUIC_FLAG_COUNT(quic_reloadable_flag_quic_truncate_long_details);
return QuicStringPiece(error.data(), kMaxErrorStringLength);
}
} // namespace net
......@@ -501,6 +501,8 @@ class QUIC_EXPORT_PRIVATE QuicFramer {
void set_detailed_error(const char* error) { detailed_error_ = error; }
QuicStringPiece TruncateErrorString(QuicStringPiece error);
std::string detailed_error_;
QuicFramerVisitorInterface* visitor_;
QuicErrorCode error_;
......
This diff is collapsed.
......@@ -1074,10 +1074,14 @@ TEST_F(QuicPacketGeneratorTest, ConnectionCloseFrameLargerThanPacketSize) {
char buf[2000] = {};
QuicStringPiece error_details(buf, 2000);
frame->error_details = error_details.as_string();
EXPECT_CALL(delegate_,
OnUnrecoverableError(QUIC_FAILED_TO_SERIALIZE_PACKET,
"Single frame cannot fit into a packet", _));
EXPECT_QUIC_BUG(generator_.AddControlFrame(QuicFrame(frame)), "");
if (FLAGS_quic_reloadable_flag_quic_truncate_long_details) {
generator_.AddControlFrame(QuicFrame(frame));
} else {
EXPECT_CALL(delegate_, OnUnrecoverableError(
QUIC_FAILED_TO_SERIALIZE_PACKET,
"Single frame cannot fit into a packet", _));
EXPECT_QUIC_BUG(generator_.AddControlFrame(QuicFrame(frame)), "");
}
EXPECT_TRUE(generator_.HasQueuedFrames());
EXPECT_TRUE(generator_.HasRetransmittableFrames());
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment