Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1318)

Unified Diff: webrtc/modules/rtp_rtcp/source/h264_sps_parser.cc

Issue 1226203002: Avoid overflow in checking for emulation bytes in rbsp. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added clarifying comment Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/rtp_rtcp/source/h264_sps_parser.cc
diff --git a/webrtc/modules/rtp_rtcp/source/h264_sps_parser.cc b/webrtc/modules/rtp_rtcp/source/h264_sps_parser.cc
index 034e761dcd4d30177d86982f47e5c8ce28508c68..d8f9afdd048f1bebb87bb0847927275e0e26b7e1 100644
--- a/webrtc/modules/rtp_rtcp/source/h264_sps_parser.cc
+++ b/webrtc/modules/rtp_rtcp/source/h264_sps_parser.cc
@@ -36,7 +36,11 @@ bool H264SpsParser::Parse() {
// section 7.3.1 of the H.264 standard.
rtc::ByteBuffer rbsp_buffer;
for (size_t i = 0; i < byte_length_;) {
- if (i + 3 < byte_length_ && sps_[i] == 0 && sps_[i + 1] == 0 &&
+ // Be careful about over/underflow here. byte_length_ - 3 can underflow, and
+ // i + 3 can overflow, but byte_length_ - i can't, because i < byte_length_
+ // above, and that expression will produce the number of bytes left in
+ // the stream including the byte at i.
+ if (byte_length_ - i >= 3 && sps_[i] == 0 && sps_[i + 1] == 0 &&
sps_[i + 2] == 3) {
// Two rbsp bytes + the emulation byte.
rbsp_buffer.WriteBytes(sps_bytes + i, 2);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698