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;
using namespace dash::exception;
AbstractAdaptationLogic::AbstractAdaptationLogic (IMPDManager *mpdManager, stream_t *stream) :
bpsAvg (-1),
bpsAvg (0),
bpsLastChunk (0),
mpdManager (mpdManager),
stream (stream),
......@@ -51,16 +51,16 @@ void AbstractAdaptationLogic::bufferLevelChanged (mtime_t bufferedMicroSec,
this->bufferedMicroSec = bufferedMicroSec;
this->bufferedPercent = bufferedPercent;
}
void AbstractAdaptationLogic::downloadRateChanged (long bpsAvg, long bpsLastChunk)
void AbstractAdaptationLogic::downloadRateChanged (uint64_t bpsAvg, uint64_t bpsLastChunk)
{
this->bpsAvg = bpsAvg;
this->bpsLastChunk = bpsLastChunk;
}
long AbstractAdaptationLogic::getBpsAvg () const
uint64_t AbstractAdaptationLogic::getBpsAvg () const
{
return this->bpsAvg;
}
long AbstractAdaptationLogic::getBpsLastChunk () const
uint64_t AbstractAdaptationLogic::getBpsLastChunk () const
{
return this->bpsLastChunk;
}
......
......@@ -47,11 +47,11 @@ namespace dash
AbstractAdaptationLogic (dash::mpd::IMPDManager *mpdManager, stream_t *stream);
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);
long getBpsAvg () const;
long getBpsLastChunk () const;
uint64_t getBpsAvg () const;
uint64_t getBpsLastChunk () const;
int getBufferPercent () const;
private:
......
......@@ -52,8 +52,8 @@ namespace dash
/**
* \return The average bitrate in bits per second.
*/
virtual long getBpsAvg () const = 0;
virtual long getBpsLastChunk () const = 0;
virtual uint64_t getBpsAvg () const = 0;
virtual uint64_t getBpsLastChunk () const = 0;
};
}
}
......
......@@ -25,6 +25,8 @@
#ifndef IDOWNLOADRATEOBSERVER_H_
#define IDOWNLOADRATEOBSERVER_H_
#include <stdint.h>
namespace dash
{
namespace logic
......@@ -32,7 +34,7 @@ namespace dash
class IDownloadRateObserver
{
public:
virtual void downloadRateChanged(long bpsAvg, long bpsLastChunk) = 0;
virtual void downloadRateChanged(uint64_t bpsAvg, uint64_t bpsLastChunk) = 0;
virtual ~IDownloadRateObserver(){}
};
}
......
......@@ -53,7 +53,7 @@ Chunk* RateBasedAdaptationLogic::getNextChunk() throw(EOFException)
if(this->currentPeriod == NULL)
throw EOFException();
long bitrate = this->getBpsAvg();
uint64_t bitrate = this->getBpsAvg();
if(this->getBufferPercent() < MINBUFFER)
bitrate = 0;
......
......@@ -72,7 +72,7 @@ void Chunk::setUseByteRange (bool value)
{
this->hasByteRange = value;
}
void Chunk::setBitrate (int bitrate)
void Chunk::setBitrate (uint64_t bitrate)
{
this->bitrate = bitrate;
}
......
......@@ -27,6 +27,7 @@
#include <vector>
#include <string>
#include <stdint.h>
namespace dash
{
......@@ -46,7 +47,7 @@ namespace dash
void addOptionalUrl (const std::string& url);
bool useByteRange ();
void setUseByteRange (bool value);
void setBitrate (int bitrate);
void setBitrate (uint64_t bitrate);
int getBitrate ();
private:
......
......@@ -114,10 +114,10 @@ int HTTPConnectionManager::read( Chunk *chunk, void *p_buffer, s
if(this->timeSecChunk > 0)
this->bpsLastChunk = (this->bytesReadChunk / this->timeSecChunk) * 8;
if(this->bpsAvg < 0 || this->chunkCount < 2)
if(this->chunkCount < 2)
this->bpsAvg = 0;
if(this->bpsLastChunk < 0 || this->chunkCount < 2)
if(this->chunkCount < 2)
this->bpsLastChunk = 0;
this->notify();
......@@ -150,7 +150,7 @@ void HTTPConnectionManager::attach (IDownloadRa
}
void HTTPConnectionManager::notify ()
{
if ( this->bpsAvg <= 0 )
if ( this->bpsAvg == 0 )
return ;
for(size_t i = 0; i < this->rateObservers.size(); i++)
this->rateObservers.at(i)->downloadRateChanged(this->bpsAvg, this->bpsLastChunk);
......
......@@ -59,8 +59,8 @@ namespace dash
std::map<Chunk *, HTTPConnection *> chunkMap;
std::map<std::string, HTTPConnection *> urlMap;
std::vector<dash::logic::IDownloadRateObserver *> rateObservers;
long bpsAvg;
long bpsLastChunk;
uint64_t bpsAvg;
uint64_t bpsLastChunk;
long bytesReadSession;
double timeSecSession;
long bytesReadChunk;
......
......@@ -91,7 +91,7 @@ Period* BasicCMManager::getFirstPeriod ()
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();
......@@ -134,7 +134,7 @@ const MPD* BasicCMManager::getMPD() const
{
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);
}
......@@ -52,9 +52,9 @@ namespace dash
Period* getNextPeriod( Period *period );
Representation* getBestRepresentation( Period *period );
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;
Representation* getRepresentation (Period *period, int bitrate,
Representation* getRepresentation (Period *period, uint64_t bitrate,
int width, int height) const;
private:
......
......@@ -52,9 +52,9 @@ namespace dash
virtual Period* getNextPeriod (Period *period) = 0;
virtual Representation* getBestRepresentation (Period *period) = 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 Representation* getRepresentation (Period *period, int bitrate,
virtual Representation* getRepresentation (Period *period, uint64_t bitrate,
int width, int height) const = 0;
};
}
......
......@@ -87,7 +87,7 @@ Period* IsoffMainManager::getFirstPeriod ()
return periods.at(0);
}
Representation* IsoffMainManager::getRepresentation (Period *period, int bitrate) const
Representation* IsoffMainManager::getRepresentation (Period *period, uint64_t bitrate) const
{
if(period == NULL)
return NULL;
......@@ -129,7 +129,7 @@ const MPD* IsoffMainManager::getMPD () const
{
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)
return NULL;
......
......@@ -52,9 +52,9 @@ namespace dash
Period* getNextPeriod (Period *period);
Representation* getBestRepresentation (Period *period);
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;
Representation* getRepresentation (Period *period, int bitrate,
Representation* getRepresentation (Period *period, uint64_t bitrate,
int width, int height) const;
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