Commit a6817c36 authored by Frédéric Yhuel's avatar Frédéric Yhuel Committed by Hugo Beauzée-Luyssen

DASH: prevent integer overflow

A integer overflow could happen in bandwidth computation, for example if
we have a DASH server and client on the same LAN.
Signed-off-by: default avatarHugo Beauzée-Luyssen <beauze.h@gmail.com>
parent 39ef23e2
...@@ -33,7 +33,7 @@ using namespace dash::mpd; ...@@ -33,7 +33,7 @@ using namespace dash::mpd;
using namespace dash::exception; using namespace dash::exception;
AbstractAdaptationLogic::AbstractAdaptationLogic (IMPDManager *mpdManager, stream_t *stream) : AbstractAdaptationLogic::AbstractAdaptationLogic (IMPDManager *mpdManager, stream_t *stream) :
bpsAvg (-1), bpsAvg (0),
bpsLastChunk (0), bpsLastChunk (0),
mpdManager (mpdManager), mpdManager (mpdManager),
stream (stream), stream (stream),
...@@ -51,16 +51,16 @@ void AbstractAdaptationLogic::bufferLevelChanged (mtime_t bufferedMicroSec, ...@@ -51,16 +51,16 @@ void AbstractAdaptationLogic::bufferLevelChanged (mtime_t bufferedMicroSec,
this->bufferedMicroSec = bufferedMicroSec; this->bufferedMicroSec = bufferedMicroSec;
this->bufferedPercent = bufferedPercent; this->bufferedPercent = bufferedPercent;
} }
void AbstractAdaptationLogic::downloadRateChanged (long bpsAvg, long bpsLastChunk) void AbstractAdaptationLogic::downloadRateChanged (uint64_t bpsAvg, uint64_t bpsLastChunk)
{ {
this->bpsAvg = bpsAvg; this->bpsAvg = bpsAvg;
this->bpsLastChunk = bpsLastChunk; this->bpsLastChunk = bpsLastChunk;
} }
long AbstractAdaptationLogic::getBpsAvg () const uint64_t AbstractAdaptationLogic::getBpsAvg () const
{ {
return this->bpsAvg; return this->bpsAvg;
} }
long AbstractAdaptationLogic::getBpsLastChunk () const uint64_t AbstractAdaptationLogic::getBpsLastChunk () const
{ {
return this->bpsLastChunk; return this->bpsLastChunk;
} }
......
...@@ -47,11 +47,11 @@ namespace dash ...@@ -47,11 +47,11 @@ namespace dash
AbstractAdaptationLogic (dash::mpd::IMPDManager *mpdManager, stream_t *stream); AbstractAdaptationLogic (dash::mpd::IMPDManager *mpdManager, stream_t *stream);
virtual ~AbstractAdaptationLogic (); virtual ~AbstractAdaptationLogic ();
virtual void downloadRateChanged (long bpsAvg, long bpsLastChunk); virtual void downloadRateChanged (uint64_t bpsAvg, uint64_t bpsLastChunk);
virtual void bufferLevelChanged (mtime_t bufferedMicroSec, int bufferedPercent); virtual void bufferLevelChanged (mtime_t bufferedMicroSec, int bufferedPercent);
long getBpsAvg () const; uint64_t getBpsAvg () const;
long getBpsLastChunk () const; uint64_t getBpsLastChunk () const;
int getBufferPercent () const; int getBufferPercent () const;
private: private:
......
...@@ -52,8 +52,8 @@ namespace dash ...@@ -52,8 +52,8 @@ namespace dash
/** /**
* \return The average bitrate in bits per second. * \return The average bitrate in bits per second.
*/ */
virtual long getBpsAvg () const = 0; virtual uint64_t getBpsAvg () const = 0;
virtual long getBpsLastChunk () const = 0; virtual uint64_t getBpsLastChunk () const = 0;
}; };
} }
} }
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#ifndef IDOWNLOADRATEOBSERVER_H_ #ifndef IDOWNLOADRATEOBSERVER_H_
#define IDOWNLOADRATEOBSERVER_H_ #define IDOWNLOADRATEOBSERVER_H_
#include <stdint.h>
namespace dash namespace dash
{ {
namespace logic namespace logic
...@@ -32,7 +34,7 @@ namespace dash ...@@ -32,7 +34,7 @@ namespace dash
class IDownloadRateObserver class IDownloadRateObserver
{ {
public: public:
virtual void downloadRateChanged(long bpsAvg, long bpsLastChunk) = 0; virtual void downloadRateChanged(uint64_t bpsAvg, uint64_t bpsLastChunk) = 0;
virtual ~IDownloadRateObserver(){} virtual ~IDownloadRateObserver(){}
}; };
} }
......
...@@ -53,7 +53,7 @@ Chunk* RateBasedAdaptationLogic::getNextChunk() throw(EOFException) ...@@ -53,7 +53,7 @@ Chunk* RateBasedAdaptationLogic::getNextChunk() throw(EOFException)
if(this->currentPeriod == NULL) if(this->currentPeriod == NULL)
throw EOFException(); throw EOFException();
long bitrate = this->getBpsAvg(); uint64_t bitrate = this->getBpsAvg();
if(this->getBufferPercent() < MINBUFFER) if(this->getBufferPercent() < MINBUFFER)
bitrate = 0; bitrate = 0;
......
...@@ -72,7 +72,7 @@ void Chunk::setUseByteRange (bool value) ...@@ -72,7 +72,7 @@ void Chunk::setUseByteRange (bool value)
{ {
this->hasByteRange = value; this->hasByteRange = value;
} }
void Chunk::setBitrate (int bitrate) void Chunk::setBitrate (uint64_t bitrate)
{ {
this->bitrate = bitrate; this->bitrate = bitrate;
} }
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <stdint.h>
namespace dash namespace dash
{ {
...@@ -46,7 +47,7 @@ namespace dash ...@@ -46,7 +47,7 @@ namespace dash
void addOptionalUrl (const std::string& url); void addOptionalUrl (const std::string& url);
bool useByteRange (); bool useByteRange ();
void setUseByteRange (bool value); void setUseByteRange (bool value);
void setBitrate (int bitrate); void setBitrate (uint64_t bitrate);
int getBitrate (); int getBitrate ();
private: private:
......
...@@ -114,10 +114,10 @@ int HTTPConnectionManager::read( Chunk *chunk, void *p_buffer, s ...@@ -114,10 +114,10 @@ int HTTPConnectionManager::read( Chunk *chunk, void *p_buffer, s
if(this->timeSecChunk > 0) if(this->timeSecChunk > 0)
this->bpsLastChunk = (this->bytesReadChunk / this->timeSecChunk) * 8; this->bpsLastChunk = (this->bytesReadChunk / this->timeSecChunk) * 8;
if(this->bpsAvg < 0 || this->chunkCount < 2) if(this->chunkCount < 2)
this->bpsAvg = 0; this->bpsAvg = 0;
if(this->bpsLastChunk < 0 || this->chunkCount < 2) if(this->chunkCount < 2)
this->bpsLastChunk = 0; this->bpsLastChunk = 0;
this->notify(); this->notify();
...@@ -150,7 +150,7 @@ void HTTPConnectionManager::attach (IDownloadRa ...@@ -150,7 +150,7 @@ void HTTPConnectionManager::attach (IDownloadRa
} }
void HTTPConnectionManager::notify () void HTTPConnectionManager::notify ()
{ {
if ( this->bpsAvg <= 0 ) if ( this->bpsAvg == 0 )
return ; return ;
for(size_t i = 0; i < this->rateObservers.size(); i++) for(size_t i = 0; i < this->rateObservers.size(); i++)
this->rateObservers.at(i)->downloadRateChanged(this->bpsAvg, this->bpsLastChunk); this->rateObservers.at(i)->downloadRateChanged(this->bpsAvg, this->bpsLastChunk);
......
...@@ -59,8 +59,8 @@ namespace dash ...@@ -59,8 +59,8 @@ namespace dash
std::map<Chunk *, HTTPConnection *> chunkMap; std::map<Chunk *, HTTPConnection *> chunkMap;
std::map<std::string, HTTPConnection *> urlMap; std::map<std::string, HTTPConnection *> urlMap;
std::vector<dash::logic::IDownloadRateObserver *> rateObservers; std::vector<dash::logic::IDownloadRateObserver *> rateObservers;
long bpsAvg; uint64_t bpsAvg;
long bpsLastChunk; uint64_t bpsLastChunk;
long bytesReadSession; long bytesReadSession;
double timeSecSession; double timeSecSession;
long bytesReadChunk; long bytesReadChunk;
......
...@@ -91,7 +91,7 @@ Period* BasicCMManager::getFirstPeriod () ...@@ -91,7 +91,7 @@ Period* BasicCMManager::getFirstPeriod ()
return periods.at(0); return periods.at(0);
} }
Representation* BasicCMManager::getRepresentation(Period *period, int bitrate ) const Representation* BasicCMManager::getRepresentation(Period *period, uint64_t bitrate ) const
{ {
std::vector<Group *> groups = period->getGroups(); std::vector<Group *> groups = period->getGroups();
...@@ -134,7 +134,7 @@ const MPD* BasicCMManager::getMPD() const ...@@ -134,7 +134,7 @@ const MPD* BasicCMManager::getMPD() const
{ {
return this->mpd; return this->mpd;
} }
Representation* BasicCMManager::getRepresentation (Period *period, int bitrate, int, int ) const Representation* BasicCMManager::getRepresentation (Period *period, uint64_t bitrate, int, int ) const
{ {
return this->getRepresentation(period, bitrate); return this->getRepresentation(period, bitrate);
} }
...@@ -52,9 +52,9 @@ namespace dash ...@@ -52,9 +52,9 @@ namespace dash
Period* getNextPeriod( Period *period ); Period* getNextPeriod( Period *period );
Representation* getBestRepresentation( Period *period ); Representation* getBestRepresentation( Period *period );
std::vector<Segment *> getSegments( const Representation *rep ); std::vector<Segment *> getSegments( const Representation *rep );
Representation* getRepresentation( Period *period, int bitrate ) const; Representation* getRepresentation( Period *period, uint64_t bitrate ) const;
const MPD* getMPD() const; const MPD* getMPD() const;
Representation* getRepresentation (Period *period, int bitrate, Representation* getRepresentation (Period *period, uint64_t bitrate,
int width, int height) const; int width, int height) const;
private: private:
......
...@@ -52,9 +52,9 @@ namespace dash ...@@ -52,9 +52,9 @@ namespace dash
virtual Period* getNextPeriod (Period *period) = 0; virtual Period* getNextPeriod (Period *period) = 0;
virtual Representation* getBestRepresentation (Period *period) = 0; virtual Representation* getBestRepresentation (Period *period) = 0;
virtual std::vector<Segment *> getSegments (const Representation *rep) = 0; virtual std::vector<Segment *> getSegments (const Representation *rep) = 0;
virtual Representation* getRepresentation (Period *period, int bitrate) const = 0; virtual Representation* getRepresentation (Period *period, uint64_t bitrate) const = 0;
virtual const MPD* getMPD () const = 0; virtual const MPD* getMPD () const = 0;
virtual Representation* getRepresentation (Period *period, int bitrate, virtual Representation* getRepresentation (Period *period, uint64_t bitrate,
int width, int height) const = 0; int width, int height) const = 0;
}; };
} }
......
...@@ -87,7 +87,7 @@ Period* IsoffMainManager::getFirstPeriod () ...@@ -87,7 +87,7 @@ Period* IsoffMainManager::getFirstPeriod ()
return periods.at(0); return periods.at(0);
} }
Representation* IsoffMainManager::getRepresentation (Period *period, int bitrate) const Representation* IsoffMainManager::getRepresentation (Period *period, uint64_t bitrate) const
{ {
if(period == NULL) if(period == NULL)
return NULL; return NULL;
...@@ -129,7 +129,7 @@ const MPD* IsoffMainManager::getMPD () const ...@@ -129,7 +129,7 @@ const MPD* IsoffMainManager::getMPD () const
{ {
return this->mpd; return this->mpd;
} }
Representation* IsoffMainManager::getRepresentation (Period *period, int bitrate, int width, int height) const Representation* IsoffMainManager::getRepresentation (Period *period, uint64_t bitrate, int width, int height) const
{ {
if(period == NULL) if(period == NULL)
return NULL; return NULL;
......
...@@ -52,9 +52,9 @@ namespace dash ...@@ -52,9 +52,9 @@ namespace dash
Period* getNextPeriod (Period *period); Period* getNextPeriod (Period *period);
Representation* getBestRepresentation (Period *period); Representation* getBestRepresentation (Period *period);
std::vector<Segment *> getSegments (const Representation *rep); std::vector<Segment *> getSegments (const Representation *rep);
Representation* getRepresentation (Period *period, int bitrate) const; Representation* getRepresentation (Period *period, uint64_t bitrate) const;
const MPD* getMPD () const; const MPD* getMPD () const;
Representation* getRepresentation (Period *period, int bitrate, Representation* getRepresentation (Period *period, uint64_t bitrate,
int width, int height) const; int width, int height) const;
private: private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment