[vlc-commits] [Git][videolan/vlc][master] demux: adaptive: check ios reads
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Fri Sep 26 15:17:50 UTC 2025
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
d3346473 by François Cartegnie at 2025-09-26T14:56:24+00:00
demux: adaptive: check ios reads
refs CID 1665601
- - - - -
4 changed files:
- modules/demux/adaptive/tools/Conversions.cpp
- modules/demux/adaptive/tools/Conversions.hpp
- modules/demux/dash/mpd/TemplatedUri.cpp
- modules/demux/hls/playlist/Tags.cpp
Changes:
=====================================
modules/demux/adaptive/tools/Conversions.cpp
=====================================
@@ -107,22 +107,24 @@ UTCTime::UTCTime(const std::string &str)
try
{
/* Date */
- for(int i=UTCTIME_YEAR;i<=UTCTIME_DAY && !in.eof();i++)
+ for(int i=UTCTIME_YEAR;i<=UTCTIME_DAY && in.good();i++)
{
if(i!=UTCTIME_YEAR)
in.ignore(1);
- in >> values[i];
+ if(in.good())
+ in >> values[i];
}
/* Time */
if (!in.eof() && in.peek() == 'T')
{
- for(int i=UTCTIME_HOUR;i<=UTCTIME_SEC && !in.eof();i++)
+ for(int i=UTCTIME_HOUR;i<=UTCTIME_SEC && in.good();i++)
{
in.ignore(1);
- in >> values[i];
+ if(in.good())
+ in >> values[i];
}
}
- if(!in.eof() && in.peek() == '.')
+ if(in.good() && in.peek() == '.')
{
in.ignore(1);
values[UTCTIME_FRAC_NUM] = 0;
@@ -133,42 +135,46 @@ UTCTime::UTCTime(const std::string &str)
values[UTCTIME_FRAC_NUM] = values[UTCTIME_FRAC_NUM] * 10 + (c - '0');
values[UTCTIME_FRAC_DEN] *= 10;
in.ignore(1);
+ if(!in.good())
+ break;
c = in.peek();
}
}
/* Timezone */
- if(!in.eof() && in.peek() == 'Z')
+ if(in.good() && in.peek() == 'Z')
{
in.ignore(1);
}
- else if (!in.eof() && (in.peek() == '+' || in.peek() == '-'))
+ else if (in.good() && (in.peek() == '+' || in.peek() == '-'))
{
int sign = (in.peek() == '+') ? 1 : -1;
int tz = 0;
in.ignore(1);
- if(!in.eof())
+ if(in.good())
{
std::string tzspec;
in >> tzspec;
-
- if(tzspec.length() >= 4)
+ if(!in.fail())
{
+ if(tzspec.length() >= 4)
+ {
tz = sign * std::stoul(tzspec.substr(0, 2)) * 60;
if(tzspec.length() == 5 && tzspec.find(':') == 2)
- tz += sign * std::stoul(tzspec.substr(3, 2));
+ tz += sign * std::stoul(tzspec.substr(3, 2));
else
- tz += sign * std::stoul(tzspec.substr(2, 2));
- }
- else
- {
+ tz += sign * std::stoul(tzspec.substr(2, 2));
+ }
+ else
+ {
tz = sign * std::stoul(tzspec) * 60;
+ }
+ values[UTCTIME_TZ] = tz;
}
- values[UTCTIME_TZ] = tz;
}
}
- if (!in.fail() && !in.bad()) {
+ if (!in.fail()) {
struct tm tm;
tm.tm_year = values[UTCTIME_YEAR] - 1900;
=====================================
modules/demux/adaptive/tools/Conversions.hpp
=====================================
@@ -50,16 +50,10 @@ template<typename T> class Integer
public:
Integer(const std::string &str)
{
- try
- {
- std::istringstream in(str);
- in.imbue(std::locale("C"));
- in >> value;
- if (in.fail() || in.bad())
- value = 0;
- } catch (...) {
+ std::istringstream in(str);
+ in.imbue(std::locale("C"));
+ if(!(in >> value))
value = 0;
- }
}
operator T() const
=====================================
modules/demux/dash/mpd/TemplatedUri.cpp
=====================================
@@ -54,12 +54,15 @@ static std::string::size_type TokenEnd(const std::string &str,
std::istringstream iss(str.substr(pos + 1, fmtend - pos));
iss.imbue(std::locale("C"));
formatwidth = 1; /* %d -> default width = 1 */
- if(std::isdigit(iss.peek())) /* [n]d */
- iss >> formatwidth;
- if (iss.peek() != 'd') /* should be trailing d */
- return std::string::npos;
- /* return end of token position */
- return fmtend;
+ if(iss.good())
+ {
+ if(std::isdigit(iss.peek())) /* [n]d */
+ iss >> formatwidth;
+ if (iss.fail() || iss.peek() != 'd') /* should be trailing d */
+ return std::string::npos;
+ /* return end of token position */
+ return fmtend;
+ }
}
}
return std::string::npos;
=====================================
modules/demux/hls/playlist/Tags.cpp
=====================================
@@ -42,8 +42,7 @@ uint64_t Attribute::decimal() const
std::istringstream is(value);
is.imbue(std::locale("C"));
uint64_t ret;
- is >> ret;
- return ret;
+ return (is >> ret) ? ret : 0;
}
double Attribute::floatingPoint() const
@@ -51,8 +50,7 @@ double Attribute::floatingPoint() const
std::istringstream is(value);
is.imbue(std::locale("C"));
double ret;
- is >> ret;
- return ret;
+ return (is >> ret) ? ret : 0;
}
std::vector<uint8_t> Attribute::hexSequence() const
@@ -65,8 +63,8 @@ std::vector<uint8_t> Attribute::hexSequence() const
unsigned val;
std::stringstream ss(value.substr(i, 2));
ss.imbue(std::locale("C"));
- ss >> std::hex >> val;
- ret.push_back(val);
+ if((ss >> std::hex) >> val)
+ ret.push_back(val);
}
}
return ret;
@@ -75,8 +73,8 @@ std::vector<uint8_t> Attribute::hexSequence() const
static inline std::istream& operator>>(std::istream& is, adaptive::optional<std::size_t>& data)
{
size_t val;
- is >> val;
- data = val;
+ if(is >> val)
+ data = val;
return is;
}
@@ -87,14 +85,16 @@ ByteRange Attribute::getByteRange() const
std::istringstream is(value);
is.imbue(std::locale("C"));
- if(!is.eof())
+ if(!is.good() || !(is >> length))
+ return ByteRange();
+
+ if(is.good())
{
- is >> length;
- if(!is.eof())
+ char c = is.get();
+ if(c == '@' && is.good())
{
- char c = is.get();
- if(c == '@' && !is.eof())
- is >> offset;
+ if(!(is >> offset))
+ return ByteRange();
}
}
@@ -107,13 +107,13 @@ std::pair<int, int> Attribute::getResolution() const
std::istringstream is(value);
is.imbue(std::locale("C"));
- if(!is.eof())
+ if(is.good())
{
is >> w;
- if(!is.eof())
+ if(is.good())
{
char c = is.get();
- if(c == 'x' && !is.eof())
+ if(c == 'x' && is.good())
is >> h;
}
}
@@ -198,10 +198,10 @@ void AttributesTag::parseAttributes(const std::string &field)
std::istringstream iss(field);
std::ostringstream oss;
- while(!iss.eof())
+ while(iss.good())
{
/* parse attribute name */
- while(!iss.eof())
+ while(iss.good())
{
char c = iss.peek();
if((c >= 'A' && c <= 'Z') || c == '-')
@@ -222,7 +222,7 @@ void AttributesTag::parseAttributes(const std::string &field)
/* parse attributes value */
bool b_quoted = false;
- while(!iss.eof())
+ while(iss.good())
{
char c = iss.peek();
if(c == '\\' && b_quoted)
@@ -249,7 +249,7 @@ void AttributesTag::parseAttributes(const std::string &field)
continue;
}
- if(!iss.eof())
+ if(iss.good())
oss.put((char)iss.get());
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/d334647303310cb8a574c6d2a2238e81f8cb8843
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/d334647303310cb8a574c6d2a2238e81f8cb8843
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list