From 2cef4d51a261982bbbeeace0a110f5c9e4e643a5 Mon Sep 17 00:00:00 2001 From: James Zern Date: Thu, 23 Mar 2017 15:40:33 -0700 Subject: [PATCH] mkvparser:Parse: s/FLT_MIN/-FLT_MAX/ FLT_MIN is the smallest finite value (numeric_limits::min()) -FLT_MAX is the correct for the most negative (numeric_limits::lowest()) http://en.cppreference.com/w/cpp/types/numeric_limits BUG=b/36255773 BUG=webm:1381 Change-Id: Iaaff611acffc3df28fef12af81ac5299791f0148 --- mkvparser/mkvparser.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mkvparser/mkvparser.cc b/mkvparser/mkvparser.cc index 63b1b7c..80814e0 100644 --- a/mkvparser/mkvparser.cc +++ b/mkvparser/mkvparser.cc @@ -4992,14 +4992,14 @@ bool PrimaryChromaticity::Parse(IMkvReader* reader, long long read_pos, const long long parse_status = UnserializeFloat(reader, read_pos, value_size, parser_value); - if (parse_status < 0 || parser_value < FLT_MIN || parser_value > FLT_MAX) + // Valid range is [0, 1]. Make sure the double is representable as a float + // before casting. + if (parse_status < 0 || parser_value < 0.0 || parser_value > 1.0 || + (parser_value > 0.0 && parser_value < FLT_MIN)) return false; *value = static_cast(parser_value); - if (*value < 0.0 || *value > 1.0) - return false; - return true; } @@ -5230,7 +5230,9 @@ bool Projection::Parse(IMkvReader* reader, long long start, long long size, double value = 0; const long long value_parse_status = UnserializeFloat(reader, read_pos, child_size, value); - if (value_parse_status < 0 || value < FLT_MIN || value > FLT_MAX) { + // Make sure value is representable as a float before casting. + if (value_parse_status < 0 || value < -FLT_MAX || value > FLT_MAX || + (value > 0.0 && value < FLT_MIN)) { return false; }