[vlc-commits] [Git][videolan/vlc][3.0.x] 4 commits: demux/adaptive: Handle failures of istringstream
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Sat Jul 3 11:11:02 UTC 2021
Jean-Baptiste Kempf pushed to branch 3.0.x at VideoLAN / VLC
Commits:
a91323ea by Marvin Scholz at 2021-07-03T10:43:14+00:00
demux/adaptive: Handle failures of istringstream
(cherry picked from commit ad82fec9d253fad0344fa682aa860ff9609bf850)
- - - - -
ae2717c9 by Marvin Scholz at 2021-07-03T10:43:14+00:00
demux/adaptive: Catch all exceptions
These catches look like they intend to catch all exceptions, not just
exceptions of integer type (which is not a common exception type).
For example all exceptions derived from std::exception would not be
caught by catch(int).
(cherry picked from commit 08ae5918414f3e82ebeb31faea52f7c772b4b3bd)
- - - - -
d1b8c674 by Francois Cartegnie at 2021-07-03T10:43:14+00:00
demux: adaptive: fix parsing of half timezone offset
(cherry picked from commit ca7bb743072f2aaa19c892b5e11438a9c3da0f51)
- - - - -
801a5090 by Francois Cartegnie at 2021-07-03T10:43:14+00:00
demux: adaptive: fix fractional part in iso 8601
(cherry picked from commit 254cc167bcafeebd003d15c9c7787b7d7f8ab2b3)
- - - - -
2 changed files:
- modules/demux/adaptive/tools/Conversions.cpp
- modules/demux/adaptive/tools/Conversions.hpp
Changes:
=====================================
modules/demux/adaptive/tools/Conversions.cpp
=====================================
@@ -98,8 +98,9 @@ IsoTime::operator mtime_t () const
UTCTime::UTCTime(const std::string &str)
{
- enum { UTCTIME_YEAR = 0, UTCTIME_MON, UTCTIME_DAY, UTCTIME_HOUR, UTCTIME_MIN, UTCTIME_SEC, UTCTIME_MSEC, UTCTIME_TZ };
- int values[8] = {0};
+ enum { UTCTIME_YEAR = 0, UTCTIME_MON, UTCTIME_DAY, UTCTIME_HOUR, UTCTIME_MIN,
+ UTCTIME_SEC, UTCTIME_FRAC_NUM, UTCTIME_FRAC_DEN, UTCTIME_TZ };
+ int values[9] = {0};
std::istringstream in(str);
in.imbue(std::locale("C"));
@@ -124,7 +125,16 @@ UTCTime::UTCTime(const std::string &str)
if(!in.eof() && in.peek() == '.')
{
in.ignore(1);
- in >> values[UTCTIME_MSEC];
+ values[UTCTIME_FRAC_NUM] = 0;
+ values[UTCTIME_FRAC_DEN] = 1;
+ int c = in.peek();
+ while(c >= '0' && c <= '9')
+ {
+ values[UTCTIME_FRAC_NUM] = values[UTCTIME_FRAC_NUM] * 10 + (c - '0');
+ values[UTCTIME_FRAC_DEN] *= 10;
+ in.ignore(1);
+ c = in.peek();
+ }
}
/* Timezone */
if(!in.eof() && in.peek() == 'Z')
@@ -133,38 +143,52 @@ UTCTime::UTCTime(const std::string &str)
}
else if (!in.eof() && (in.peek() == '+' || in.peek() == '-'))
{
- int i, tz = (in.peek() == '+') ? -60 : +60;
+ int sign = (in.peek() == '+') ? 1 : -1;
+ int tz = 0;
in.ignore(1);
+
if(!in.eof())
{
- in >> i;
- tz *= i;
- in.ignore(1);
- if(!in.eof())
+ std::string tzspec;
+ in >> tzspec;
+
+ if(tzspec.length() >= 4)
{
- in >> i;
- tz += i;
+ tz = sign * std::stoul(tzspec.substr(0, 2)) * 60;
+ if(tzspec.length() == 5 && tzspec.find(':') == 2)
+ tz += sign * std::stoul(tzspec.substr(3, 2));
+ else
+ tz += sign * std::stoul(tzspec.substr(2, 2));
+ }
+ else
+ {
+ tz = sign * std::stoul(tzspec) * 60;
}
values[UTCTIME_TZ] = tz;
}
}
- struct tm tm;
-
- tm.tm_year = values[UTCTIME_YEAR] - 1900;
- tm.tm_mon = values[UTCTIME_MON] - 1;
- tm.tm_mday = values[UTCTIME_DAY];
- tm.tm_hour = values[UTCTIME_HOUR];
- tm.tm_min = values[UTCTIME_MIN];
- tm.tm_sec = values[UTCTIME_SEC];
- tm.tm_isdst = 0;
-
- t = timegm( &tm );
- t += values[UTCTIME_TZ] * 60;
- t *= 1000;
- t += values[UTCTIME_MSEC];
- t *= CLOCK_FREQ / 1000;
- } catch(int) {
+ if (!in.fail() && !in.bad()) {
+ struct tm tm;
+
+ tm.tm_year = values[UTCTIME_YEAR] - 1900;
+ tm.tm_mon = values[UTCTIME_MON] - 1;
+ tm.tm_mday = values[UTCTIME_DAY];
+ tm.tm_hour = values[UTCTIME_HOUR];
+ tm.tm_min = values[UTCTIME_MIN];
+ tm.tm_sec = values[UTCTIME_SEC];
+ tm.tm_isdst = 0;
+
+ int64_t st = timegm( &tm );
+ st += values[UTCTIME_TZ] * -60;
+ t = st * CLOCK_FREQ;
+ if(values[UTCTIME_FRAC_DEN] > 0)
+ t += CLOCK_FREQ * values[UTCTIME_FRAC_NUM] / values[UTCTIME_FRAC_DEN];
+ } else {
+ // Failure parsing time string
+ t = 0;
+ }
+ } catch(...) {
t = 0;
}
}
=====================================
modules/demux/adaptive/tools/Conversions.hpp
=====================================
@@ -54,7 +54,9 @@ template<typename T> class Integer
std::istringstream in(str);
in.imbue(std::locale("C"));
in >> value;
- } catch (int) {
+ if (in.fail() || in.bad())
+ value = 0;
+ } catch (...) {
value = 0;
}
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6ac4fd9e839979f1832f56ba7f832a5277231ab3...801a5090e9ba39cf5661d8aa5907da3ee0def9f9
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6ac4fd9e839979f1832f56ba7f832a5277231ab3...801a5090e9ba39cf5661d8aa5907da3ee0def9f9
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list