Open
[ArkWeb][安全][上游社区漏洞修复] 修复 Chromium issue 570927027: Fail EncodeFec when packets are passed radically out of order #151
ringking0Add on Oct 29
[ArkWeb][安全][上游社区漏洞修复] 修复 Chromium issue 570927027: Fail EncodeFec when packets are passed radically out of order #151
Open
Total: 3 files changed+59-4
| @@ -482,6 +482,7 @@ rtc_library("mock_rtp_rtcp") { | |||
| 482 | ":rtp_rtcp", | 482 | ":rtp_rtcp", |
| 483 | ":rtp_rtcp_format", | 483 | ":rtp_rtcp_format", |
| 484 | "..:module_fec_api", | 484 | "..:module_fec_api", |
| 485 | + "../../rtc_base:byte_order", | ||
| 485 | "../../api:array_view", | 486 | "../../api:array_view", |
| 486 | "../../api:rtp_headers", | 487 | "../../api:rtp_headers", |
| 487 | "../../api/transport:network_control", | 488 | "../../api/transport:network_control", |
| @@ -294,9 +294,13 @@ int ForwardErrorCorrection::InsertZerosInPacketMasks( | |||
| 294 | size_t old_bit_index = 1; | 294 | size_t old_bit_index = 1; |
| 295 | // Insert zeros in the bit mask for every hole in the sequence. | 295 | // Insert zeros in the bit mask for every hole in the sequence. |
| 296 | while (media_packets_it != media_packets.end()) { | 296 | while (media_packets_it != media_packets.end()) { |
| 297 | - if (new_bit_index == max_media_packets) { | 297 | + if (new_bit_index >= max_media_packets) { |
| 298 | - // We can only cover up to 48 packets. | 298 | + // `total_missing_seq_nums` calculation above should ensure all |
| 299 | - break; | 299 | + // `media_packets` fit within the `max_media_packets`. That calculation is |
| 300 | + // simple and fast normally, but wrong when sequence numbers wrap around | ||
| 301 | + // a lot. This condition catches exactly that - when number of packets | ||
| 302 | + // to protect turned to be larger than earlier estimated. | ||
| 303 | + return -1; | ||
| 300 | } | 304 | } |
| 301 | uint16_t seq_num = ParseSequenceNumber((*media_packets_it)->data.data()); | 305 | uint16_t seq_num = ParseSequenceNumber((*media_packets_it)->data.data()); |
| 302 | const int num_zeros_to_insert = | 306 | const int num_zeros_to_insert = |
| @@ -305,8 +309,11 @@ int ForwardErrorCorrection::InsertZerosInPacketMasks( | |||
| 305 | internal::InsertZeroColumns(num_zeros_to_insert, tmp_packet_masks_, | 309 | internal::InsertZeroColumns(num_zeros_to_insert, tmp_packet_masks_, |
| 306 | tmp_packet_mask_size, num_fec_packets, | 310 | tmp_packet_mask_size, num_fec_packets, |
| 307 | new_bit_index); | 311 | new_bit_index); |
| 312 | + new_bit_index += num_zeros_to_insert; | ||
| 313 | + if (new_bit_index >= max_media_packets) { | ||
| 314 | + return -1; | ||
| 315 | + } | ||
| 308 | } | 316 | } |
| 309 | - new_bit_index += num_zeros_to_insert; | ||
| 310 | internal::CopyColumn(tmp_packet_masks_, tmp_packet_mask_size, packet_masks_, | 317 | internal::CopyColumn(tmp_packet_masks_, tmp_packet_mask_size, packet_masks_, |
| 311 | packet_mask_size_, num_fec_packets, new_bit_index, | 318 | packet_mask_size_, num_fec_packets, new_bit_index, |
| 312 | old_bit_index); | 319 | old_bit_index); |
| @@ -25,14 +25,19 @@ | |||
| 25 | #include "modules/rtp_rtcp/source/forward_error_correction.h" | 25 | #include "modules/rtp_rtcp/source/forward_error_correction.h" |
| 26 | #include "modules/rtp_rtcp/source/forward_error_correction_internal.h" | 26 | #include "modules/rtp_rtcp/source/forward_error_correction_internal.h" |
| 27 | #include "modules/rtp_rtcp/source/ulpfec_header_reader_writer.h" | 27 | #include "modules/rtp_rtcp/source/ulpfec_header_reader_writer.h" |
| 28 | +#include "rtc_base/byte_order.h" | ||
| 28 | #include "rtc_base/checks.h" | 29 | #include "rtc_base/checks.h" |
| 29 | #include "rtc_base/random.h" | 30 | #include "rtc_base/random.h" |
| 31 | +#include "test/gmock.h" | ||
| 30 | #include "test/gtest.h" | 32 | #include "test/gtest.h" |
| 31 | 33 | ||
| 32 | namespace webrtc { | 34 | namespace webrtc { |
| 33 | 35 | ||
| 34 | namespace { | 36 | namespace { |
| 35 | 37 | ||
| 38 | +using ::testing::IsEmpty; | ||
| 39 | +using ::testing::SizeIs; | ||
| 40 | + | ||
| 36 | // Transport header size in bytes. Assume UDP/IPv4 as a reasonable minimum. | 41 | // Transport header size in bytes. Assume UDP/IPv4 as a reasonable minimum. |
| 37 | constexpr size_t kTransportOverhead = 28; | 42 | constexpr size_t kTransportOverhead = 28; |
| 38 | 43 | ||
| @@ -267,6 +272,48 @@ TYPED_TEST(RtpFecTest, | |||
| 267 | EXPECT_TRUE(this->generated_fec_packets_.empty()); | 272 | EXPECT_TRUE(this->generated_fec_packets_.empty()); |
| 268 | } | 273 | } |
| 269 | 274 | ||
| 275 | +TYPED_TEST(RtpFecTest, | ||
| 276 | + WillNotProtectMediaPacketsWithOutOfOrderWrappedSequenceNumbers) { | ||
| 277 | + ForwardErrorCorrection::PacketList media_packets = | ||
| 278 | + this->media_packet_generator_.ConstructMediaPackets(3); | ||
| 279 | + ASSERT_THAT(media_packets, SizeIs(3)); | ||
| 280 | + // Set RTP sequence numbers. | ||
| 281 | + auto it = media_packets.begin(); | ||
| 282 | + SetBE16((**(it++)).data.AsMutableSpan().subspan(2), 0); | ||
| 283 | + SetBE16((**(it++)).data.AsMutableSpan().subspan(2), 47); | ||
| 284 | + // Sequence number = 2^16 + 20 after wrap around become 20. | ||
| 285 | + SetBE16((**(it++)).data.AsMutableSpan().subspan(2), 20); | ||
| 286 | + | ||
| 287 | + std::list<ForwardErrorCorrection::Packet*> generated_fec_packets; | ||
| 288 | + EXPECT_LT(this->fec_.EncodeFec(media_packets, /*protection_factor=*/127, | ||
| 289 | + /*num_important_packets=*/3, | ||
| 290 | + /*use_unequal_protection=*/false, | ||
| 291 | + kFecMaskBursty, &generated_fec_packets), | ||
| 292 | + 0); | ||
| 293 | + EXPECT_THAT(generated_fec_packets, IsEmpty()); | ||
| 294 | +} | ||
| 295 | + | ||
| 296 | +TYPED_TEST(RtpFecTest, | ||
| 297 | + WillNotProtectMediaPacketsWithOutOfOrderWrappedSequenceNumbers2) { | ||
| 298 | + ForwardErrorCorrection::PacketList media_packets = | ||
| 299 | + this->media_packet_generator_.ConstructMediaPackets(3); | ||
| 300 | + ASSERT_THAT(media_packets, SizeIs(3)); | ||
| 301 | + // Set RTP sequence numbers. | ||
| 302 | + auto it = media_packets.begin(); | ||
| 303 | + SetBE16((**(it++)).data.AsMutableSpan().subspan(2), 0); | ||
| 304 | + SetBE16((**(it++)).data.AsMutableSpan().subspan(2), 46); | ||
| 305 | + // Sequence number = 2^16 + 20 after wrap around become 20. | ||
| 306 | + SetBE16((**(it++)).data.AsMutableSpan().subspan(2), 20); | ||
| 307 | + | ||
| 308 | + std::list<ForwardErrorCorrection::Packet*> generated_fec_packets; | ||
| 309 | + EXPECT_LT(this->fec_.EncodeFec(media_packets, /*protection_factor=*/127, | ||
| 310 | + /*num_important_packets=*/3, | ||
| 311 | + /*use_unequal_protection=*/false, | ||
| 312 | + kFecMaskBursty, &generated_fec_packets), | ||
| 313 | + 0); | ||
| 314 | + EXPECT_THAT(generated_fec_packets, IsEmpty()); | ||
| 315 | +} | ||
| 316 | + | ||
| 270 | TYPED_TEST(RtpFecTest, FecRecoveryNoLoss) { | 317 | TYPED_TEST(RtpFecTest, FecRecoveryNoLoss) { |
| 271 | constexpr int kNumImportantPackets = 0; | 318 | constexpr int kNumImportantPackets = 0; |
| 272 | constexpr bool kUseUnequalProtection = false; | 319 | constexpr bool kUseUnequalProtection = false; |