Check arrayview is not empty before accessing it
Bug: webrtc:353764813
No-Try: True
Change-Id: I873f115c13e23d827f3967bc505da4b9d1a70753
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/357580
Reviewed-by: Sergey Silkin <ssilkin@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42657}
diff --git a/common_video/h264/h264_bitstream_parser.cc b/common_video/h264/h264_bitstream_parser.cc
index 38cf0ff..5c0ebb8 100644
--- a/common_video/h264/h264_bitstream_parser.cc
+++ b/common_video/h264/h264_bitstream_parser.cc
@@ -307,6 +307,9 @@
}
void H264BitstreamParser::ParseSlice(rtc::ArrayView<const uint8_t> slice) {
+ if (slice.empty()) {
+ return;
+ }
H264::NaluType nalu_type = H264::ParseNaluType(slice[0]);
switch (nalu_type) {
case H264::NaluType::kSps: {
diff --git a/common_video/h264/sps_vui_rewriter.cc b/common_video/h264/sps_vui_rewriter.cc
index 07b5805..fa824a5 100644
--- a/common_video/h264/sps_vui_rewriter.cc
+++ b/common_video/h264/sps_vui_rewriter.cc
@@ -238,7 +238,9 @@
nalu_index.payload_start_offset - nalu_index.start_offset);
rtc::ArrayView<const uint8_t> nalu = buffer.subview(
nalu_index.payload_start_offset, nalu_index.payload_size);
-
+ if (nalu.empty()) {
+ continue;
+ }
if (H264::ParseNaluType(nalu[0]) == H264::NaluType::kSps) {
// Check if stream uses picture order count type 0, and if so rewrite it
// to enable faster decoding. Streams in that format incur additional