[vlc-commits] demux/adaptive: Handle failures of istringstream

Marvin Scholz git at videolan.org
Thu Nov 29 16:37:10 CET 2018


vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Mon Oct 29 12:42:23 2018 +0100| [ad82fec9d253fad0344fa682aa860ff9609bf850] | committer: Marvin Scholz

demux/adaptive: Handle failures of istringstream

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ad82fec9d253fad0344fa682aa860ff9609bf850
---

 modules/demux/adaptive/tools/Conversions.cpp | 31 ++++++++++++++++------------
 modules/demux/adaptive/tools/Conversions.hpp |  2 ++
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/modules/demux/adaptive/tools/Conversions.cpp b/modules/demux/adaptive/tools/Conversions.cpp
index 213fbb2bcc..e0e3764b20 100644
--- a/modules/demux/adaptive/tools/Conversions.cpp
+++ b/modules/demux/adaptive/tools/Conversions.cpp
@@ -149,21 +149,26 @@ UTCTime::UTCTime(const std::string &str)
             }
         }
 
-        struct tm tm;
+        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;
+            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 mst = timegm( &tm );
-        mst += values[UTCTIME_TZ] * 60;
-        mst *= 1000;
-        mst += values[UTCTIME_MSEC];
-        t = VLC_TICK_FROM_MS(mst);
+            int64_t mst = timegm( &tm );
+            mst += values[UTCTIME_TZ] * 60;
+            mst *= 1000;
+            mst += values[UTCTIME_MSEC];
+            t = VLC_TICK_FROM_MS(mst);
+        } else {
+            // Failure parsing time string
+            t = 0;
+        }
     } catch(int) {
         t = 0;
     }
diff --git a/modules/demux/adaptive/tools/Conversions.hpp b/modules/demux/adaptive/tools/Conversions.hpp
index 003d838ee5..4e4acee80a 100644
--- a/modules/demux/adaptive/tools/Conversions.hpp
+++ b/modules/demux/adaptive/tools/Conversions.hpp
@@ -55,6 +55,8 @@ template<typename T> class Integer
                 std::istringstream in(str);
                 in.imbue(std::locale("C"));
                 in >> value;
+                if (in.fail() || in.bad())
+                    value = 0;
             } catch (int) {
                 value = 0;
             }



More information about the vlc-commits mailing list