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

Unified Diff: media/filters/h264_parser.cc

Issue 1865203002: Avoid integer overflow errors when parsing Exp-Golomb codes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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: media/filters/h264_parser.cc
diff --git a/media/filters/h264_parser.cc b/media/filters/h264_parser.cc
index d751de77fcaa06ebdabee2ca130385189b2fc80b..4aa511ffa9f4909c601b37fb9ccb02ad7f888f58 100644
--- a/media/filters/h264_parser.cc
+++ b/media/filters/h264_parser.cc
@@ -2,13 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "media/filters/h264_parser.h"
+
+#include <limits>
+
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/stl_util.h"
-
#include "media/base/decrypt_config.h"
-#include "media/filters/h264_parser.h"
namespace media {
@@ -318,8 +320,14 @@ H264Parser::Result H264Parser::ReadUE(int* val) {
return kInvalidStream;
// Calculate exp-Golomb code value of size num_bits.
- *val = (1 << num_bits) - 1;
+ // Special case for |num_bits| == 31 to avoid integer overflow.
+ if (num_bits == 31) {
sandersd (OOO until July 31) 2016/04/07 01:26:09 Add a comment to the first line explaining that we
jrummell 2016/04/07 01:49:19 Done.
+ *val = std::numeric_limits<int>::max();
jrummell 2016/04/07 01:09:32 Since we're checking for 2^31-1 explicitly, I deba
sandersd (OOO until July 31) 2016/04/07 01:26:09 What we should actually be doing is rewriting H264
jrummell 2016/04/07 01:49:19 Done.
+ READ_BITS_OR_RETURN(num_bits, &rest);
+ return (rest == 0) ? kOk : kInvalidStream;
+ }
+ *val = (1 << num_bits) - 1;
if (num_bits > 0) {
READ_BITS_OR_RETURN(num_bits, &rest);
*val += rest;
« 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