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

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: 1u 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
« media/filters/h264_bit_reader.cc ('K') | « media/filters/h264_bit_reader.cc ('k') | 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..0fcd1fa5cd7804ea88d06db29d713df45667e0ae 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,7 +320,15 @@ 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. The only
+ // valid representation as an int is 2^31 - 1, so the remaining bits must
+ // be 0 or else the number is too large.
+ *val = (1u << num_bits) - 1;
sandersd (OOO until July 31) 2016/04/07 20:48:09 Both ones should be 1u.
jrummell 2016/04/07 21:13:59 Done.
+
+ if (num_bits == 31) {
+ READ_BITS_OR_RETURN(num_bits, &rest);
+ return (rest == 0) ? kOk : kInvalidStream;
+ }
if (num_bits > 0) {
READ_BITS_OR_RETURN(num_bits, &rest);
« media/filters/h264_bit_reader.cc ('K') | « media/filters/h264_bit_reader.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698